Why is an anonymous inner class containing nothing generated from this code?

Posted by Andrew Westberg on Stack Overflow See other posts from Stack Overflow or by Andrew Westberg
Published on 2010-05-21T15:00:37Z Indexed on 2010/05/21 15:00 UTC
Read the original article Hit count: 224

When run through javac on the cmd line 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?


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();
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about inner-classes