Frage

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.

War es hilfreich?

Lösung

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

Example:

public class TestInnerOuterClass {
    class TestInnerChild{

    }

    Serializable annoymousTest = new Serializable() {
    };
}

Classes which will generated are:

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

Andere Tipps

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

These class files correspond to anonymous inner classes that you use in the program.

Here's an example of an event handler that will be compiled into .class file of its own:

button.addActionLister(new ActionListener() {
    public void actionPerformed(ActionEvent e) { .... }
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top