Anonymity and observability of unnamed classes (JEP 445)

Attila Kelemen attila.kelemen85 at gmail.com
Sun May 7 23:43:40 UTC 2023


> As i said, once you have compiled the file, you get a class and you can use it the way you want.
>

I actually can't necessarily do that, if I want to stick to "I don't
know the class name". This is because there can be multiple class
files. In fact, there can be multiple class files with a valid main.
Because this works today (and I would expect it to work with unnamed
classes):

```
public class TestMain {
  public static class InnerMain {
    public static void main(String[] args) {
      System.out.println("inner main");
    }
  }

  public static void main(String[] args) {
    System.out.println("outer main");
  }
}
```

and prints "outer main". Of course, if I didn't care about treating
these classes as unnamed. Obviously, I could just check the logic of
how the file names are generated in practice, and could rely on this
undefined behavior, but I don't want to rely on undefined behavior.
Especially not to save a very small amount of boiler plate.


More information about the jdk-dev mailing list