Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 573
MichalB Avatar asked Dec 27 '22 02:12

MichalB


2 Answers

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
like image 197
Jainendra Avatar answered Jan 07 '23 04:01

Jainendra


The dollar sign is used by the compiler for inner classes.

$ sign represents inner classes. If it has a number after $ then it is an annonymous inner class. If it has a name after $ then it is only an inner class.

So in your casese these are representing annonymouse inner classes

like image 37
stinepike Avatar answered Jan 07 '23 04:01

stinepike