Behaviour change between Java 8 and Java 9 javac
Alex Buckley
alex.buckley at oracle.com
Tue Jul 18 20:00:27 UTC 2017
This is an intended change, see
https://bugs.openjdk.java.net/browse/JDK-8034044.
I confess that I am unable to find anything about this user-visible
change in the early-access JDK 9 Release Notes
(http://jdk.java.net/9/release-notes).
Alex
On 7/18/2017 12:52 PM, Ronald Servant wrote:
> Hi,
> We have noticed a change in how java9 and java8 javac compile classes
> with static anonymous inner classes.
> With the java8 compiler, static anonymous inner classes have a static
> modifier, but with the java9 javac they do not. We are unclear as to
> whether this is an intended change or a defect with the newer compiler.
> Is an intended behaviour change?
> The following code sample displays the issue:
> ---------------------------------------------
> import java.lang.reflect.Modifier;
> public class TestStaticModifier {
> static Object staticInnerAnonymousObject = new Object() {};
> static Class<?> staticInnerAnonymousClazz =
> staticInnerAnonymousObject.getClass();
>
> public static void main(String[] args) {
> TestStaticModifier tsm = new TestStaticModifier();
> getClassInfoStatic(staticInnerAnonymousClazz);
> }
>
> public static void getClassInfoStatic(Class<?> clazz) {
> System.out.println("Name : " + clazz.getName());
> System.out.println("Anonymous : " + clazz.isAnonymousClass());
> System.out.println("static ? " +
> Modifier.isStatic(clazz.getModifiers()));
> }
>
> }
> ---------------------------------------------
> With java8:
> java version "1.8.0_131"
> Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
> Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
> javac generates the following in the classfile:
> InnerClasses:
> static #20; //class TestStaticModifier$1
>
> When the program is run it outputs:
> Name : TestStaticModifier$1
> Anonymous : true
> static ? true
>
> With java9:
> openjdk version "9-internal"
> OpenJDK Runtime Environment (build 9-internal+0-adhoc.arnold.jdk9175)
> OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.arnold.jdk9175, mixed
> mode)
> javac generates the following in the classfile:
> InnerClasses:
> #20; // class TestStaticModifier$1
> When the program is run it outputs:
> Name : TestStaticModifier$1
> Anonymous : true
> static ? false
>
More information about the compiler-dev
mailing list