Home >Java >javaTutorial >Why do Java compiled classes contain names like \'Find$1.class\'?
Denoting Inner Classes in Java Compiled Classes
In Java, when exporting an application to a JAR file, certain classes may contain the class name followed by a dollar sign and a number, such as Find$1.class. This occurs because Java compiles inner classes, including anonymous inner classes, separately from the main class.
Inner classes, defined within another class, enable object-oriented programming concepts like encapsulation and code reusability. They are compiler-generated and their class files have the following naming convention:
For instance, in the following code:
<code class="java">public class OuterClass { public class InnerClass { // ... } public static void main(String[] args) { OuterClass.InnerClass inner = new InnerClass(); } }</code>
Compilation will generate the following class files:
The dollar sign in class file names serves as a separator to differentiate between outer and inner classes. It indicates that the inner class belongs to the specified outer class.
The above is the detailed content of Why do Java compiled classes contain names like \'Find$1.class\'?. For more information, please follow other related articles on the PHP Chinese website!