Having classes A and B such that:
------------A.java-------------------------------
public class A {
public static class A1 {}
}
------------B.java------------------------------
import java.util.List;
public class B {
void m(List<A.A1> a) {}
}
The class B.class will be:
InnerClasses:
public static #12= #11 of #20; //A1=class A$A1 of class A
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #3.#17 // java/lang/Object."<init>":()V
#2 = Class #18 // B
#3 = Class #19 // java/lang/Object
#4 = Utf8 <init>
#5 = Utf8 ()V
#6 = Utf8 Code
#7 = Utf8 LineNumberTable
#8 = Utf8 m
#9 = Utf8 (Ljava/util/List;)V
#10 = Utf8 Signature
#11 = Class #21 // A$A1
#12 = Utf8 A1
#13 = Utf8 InnerClasses
#14 = Utf8 (Ljava/util/List<LA$A1;>;)V
#15 = Utf8 SourceFile
#16 = Utf8 B.java
#17 = NameAndType #4:#5 // "<init>":()V
#18 = Utf8 B
#19 = Utf8 java/lang/Object
#20 = Class #22 // A
#21 = Utf8 A$A1
#22 = Utf8 A
{
public B();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 3: 0
void m(java.util.List<A$A1>);
descriptor: (Ljava/util/List;)V
flags:
Code:
stack=0, locals=2, args_size=2
0: return
LineNumberTable:
line 6: 0
Signature: #14 // (Ljava/util/List<LA$A1;>;)V
}
The only reference to the inner class (A.A1) is actually from the InnerClasses attribute. Unless the JVM or a reflection library uses it, it is in principle unnecessary and shouldn't be generated.
------------A.java-------------------------------
public class A {
public static class A1 {}
}
------------B.java------------------------------
import java.util.List;
public class B {
void m(List<A.A1> a) {}
}
The class B.class will be:
InnerClasses:
public static #12= #11 of #20; //A1=class A$A1 of class A
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #3.#17 // java/lang/Object."<init>":()V
#2 = Class #18 // B
#3 = Class #19 // java/lang/Object
#4 = Utf8 <init>
#5 = Utf8 ()V
#6 = Utf8 Code
#7 = Utf8 LineNumberTable
#8 = Utf8 m
#9 = Utf8 (Ljava/util/List;)V
#10 = Utf8 Signature
#11 = Class #21 // A$A1
#12 = Utf8 A1
#13 = Utf8 InnerClasses
#14 = Utf8 (Ljava/util/List<LA$A1;>;)V
#15 = Utf8 SourceFile
#16 = Utf8 B.java
#17 = NameAndType #4:#5 // "<init>":()V
#18 = Utf8 B
#19 = Utf8 java/lang/Object
#20 = Class #22 // A
#21 = Utf8 A$A1
#22 = Utf8 A
{
public B();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 3: 0
void m(java.util.List<A$A1>);
descriptor: (Ljava/util/List;)V
flags:
Code:
stack=0, locals=2, args_size=2
0: return
LineNumberTable:
line 6: 0
Signature: #14 // (Ljava/util/List<LA$A1;>;)V
}
The only reference to the inner class (A.A1) is actually from the InnerClasses attribute. Unless the JVM or a reflection library uses it, it is in principle unnecessary and shouldn't be generated.
- relates to
-
JDK-6673869 Wrong result of TypeElement.getNestingKind for pre-1.5 classfiles
- Open
-
JDK-8009995 javac, class file library should remove unused entries in the constant pool
- Open