Anonymity and observability of unnamed classes (JEP 445)
forax at univ-mlv.fr
forax at univ-mlv.fr
Sat May 6 19:08:14 UTC 2023
----- Original Message -----
> From: "attila kelemen85" <attila.kelemen85 at gmail.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "jdk-dev" <jdk-dev at openjdk.org>
> Sent: Saturday, May 6, 2023 8:09:58 PM
> Subject: Re: Anonymity and observability of unnamed classes (JEP 445)
> Thanks Remi, that answers most of my questions.
>
>> There is a name, but it is not well defined, like an anonymous class has a name.
>
> I guess that is a little unfortunate, because I was thinking about
> loading the class myself (say, in a test), but this way I would not
> for the same reason I would not load `MyClass$5` even though
> technically possible.
If you compile the source code with javac, you can observe the name of the unnamed class by finding the ".class" file.
>
>> Since Java 11, you do not need a class name to run a class, you can specify the
>> file name, e.g. java foo.java, it will compile the class in memory and then
>> execute it's method main.
>
> This I know, but then I think your response implies that it is not
> very reasonable to use unnamed classes in normal applications, because
> there I'm not passing a .java file, but passing a bunch of jars and
> specifying the main class for `java` (either through command line or.a
> jar's manifest).
If you want applications and jars, i think you are not "programming-in-the-small" as the JEP call it.
As you notice, unnamed classes are not very suitable for what you want.
cheers,
Rémi
More information about the jdk-dev
mailing list