On Wed, 17 Feb 2021 17:24:50 GMT, Claes Redestad <redes...@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

Reply via email to