package com.test;
public class OuterClass {
public class InnerClass {
public class InnerInnerClass {
}
}
public class InnerClass2 {
}
//this class should not exist in OuterClass after dummifying
private class PrivateInnerClass {
private String getString() {
return "hello PrivateInnerClass";
}
}
public String getStringFromPrivateInner() {
return new PrivateInnerClass().getString();
}
}
When run through javac on the command line with Sun JVM 1.6.0_20, this code produces 6 .class files:
OuterClass.class
OuterClass$1.class
OuterClass$InnerClass.class
OuterClass$InnerClass2.class
OuterClass$InnerClass$InnerInnerClass.class
OuterClass$PrivateInnerClass.class
When run through JDT in eclipse, it produces only 5 classes.
OuterClass.class
OuterClass$1.class
OuterClass$InnerClass.class
OuterClass$InnerClass2.class
OuterClass$InnerClass$InnerInnerClass.class
OuterClass$PrivateInnerClass.class
When decompiled, OuterClass$1.class contains nothing. Where is this extra class coming from and why is it created?
I don’t have the answer, but I’m able to confirm that, and reduce the snippet to the following:
This creates
OuterClass$1.classAnd here’s
javap -cforOuterClass.class:And for
OuterClass$PrivateInnerClass:As you can see, the synthesized constructor takes an
OuterClass$1argument.So
javaccreates the default constructor to take an extra argument, of type$1, and the value of that default argument is5: aconst_null.I’ve found that
$1doesn’t get created if either of the following is true:public class PrivateInnerClassPrivateInnerClassnewon itstaticnested, etc).Possibly related