RFR: 8261880: Change nested classes in java.base to static nested classes where possible [v2]

Rémi Forax github.com+828220+forax at openjdk.java.net
Wed Feb 17 17:44:47 UTC 2021


On Wed, 17 Feb 2021 17:24:50 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> For static methods, since in java language you cannot declare static method in instance inner classes, I'd say making them static makes more sense language-wise. Also making them static reduces compiler synthetic instance field and constructors.
>
> Incidentally, Java-the-language allows static methods in inner instance classes since JDK 16. And I'm not sure this was ever a restriction at the JVMS level since we've been generating static methods (using ASM) into these inner instance classes since at least JDK 9.

Inner classes doesn't really exist for the JVM, it's just an attribute (in fact, a pair of attributes) that is read/write by javac (it's very similar to the way generics work).
So it is Ok to have static methods in inner classes since Java 1.1 from the JVM POV with the caveat that you may not be all to call them from Java-the-language.
Also since Java 11, inner classes are also nestmate and those attributes (NestHost/NestMembers) change the behavior of the VM.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2589


More information about the security-dev mailing list