Search code examples
javaeclipseclassbin

Why do I have so many CLASS files in bin folder?


I have a Java project operated in Eclipse with the main executable file called GreatPlaces.java. In my /bin folder, I would assume to have just one CLASS file called GreatPlaces.class. However, I have couple of them, except for GreatPlaces.class I have also GreatPlaces$1.class, GreatPlaces$2.class ... GreatPlaces$22.class. Can anyone explain me this? Thanks.


Solution

  • Inner classes if any present in your class will be compiled and the class file will be ClassName$InnerClassName. In the case of Anonymous inner classes, it will appear as numbers.

    Example:

    public class TestInnerOuterClass {
        class TestInnerChild{
            
        }
        
        Serializable annoymousTest = new Serializable() {
        };
    }
    

    For the above code, the classes that will be generated are:

    1. TestInnerOuterClass.class
    2. TestInnerOuterClass$TestInnerChild.class
    3. TestInnerOuterCasss$1.class