3 .class files generated for 1 .java file

From: qazmlp (qazmlp1209_at_rediffmail.com)
Date: 01/18/04


Date: 18 Jan 2004 08:44:02 -0800

I wrote the following code to get more type-safe C++-equivalent enum in Java.
Whenever I compile this code, 3 class files are generated. Why?
testClass$1.class
testClass$State.class
testClass.class

I expected only 1 class, 'testClass.class' to be generated. I do not understand
why other two classes(mainly testClass$1.class) are generated additionally.
Please clarify.

------testClass.java------
public class testClass
{
  public static class State
  {
    private final String StateStr ;
    private State(String StateStr ) { this.StateStr = StateStr ; }
    public String toString() { return StateStr ; }
    public final boolean equals(Object that)
    {
      return super.equals(that);
    }
    public final int hashCode()
    {
      return super.hashCode();
    }
  }

  public static final State STATE_ONE = new State( "STATE_ONE" ) ;
  public static final State STATE_TWO = new State( "STATE_TWO" ) ;
}
------testClass.java------



Relevant Pages

  • Q: Java source and directory structure - standard way ?
    ... When I compile I use the -d option on Sun's SDK... ... and places the class files into it. ... Java source. ... code directory structure has been created to mirror the package names. ...
    (comp.lang.java)
  • 3 .class files generated for 1 .java file
    ... I wrote the following code to get more type-safe C++-equivalent enum in Java. ... Whenever I compile this code, 3 class files are generated. ...
    (comp.lang.java.programmer)
  • Re: multiple source files
    ... C++ I would have separate translation units ... I would then compile those translation ... is approached in java because I really don't ... In Java you just compile the source files to class files, ...
    (comp.lang.java.programmer)
  • Re: multiple source files
    ... C++ I would have separate translation units ... I would then compile those translation ... is approached in java because I really don't ... After you get the .class files, you link the .class files into larger execution units called .jar files. ...
    (comp.lang.java.programmer)
  • Re: multiple source files
    ... C++ I would have separate translation units ... I would then compile those translation ... is approached in java because I really don't ... In addition to the others' advice, which cover the primary points, both the "loose" class files and the internal structure of a JAR file follow Java's package structures, and strictures. ...
    (comp.lang.java.programmer)