I’ve been using Eclipse as my IDE. I also use it to export my application into a JAR file. When I look at my classes in the JAR file, a few of my classes contain the name of that class, a dollar sign, then a number. For example:
Find$1.class
Find$2.class
Find$3.class
Find.class
I’ve noticed it does this on bigger classes. Is this because the classes get so big, it compiles it into multiple classes? I’ve googled and looked on multiple forums, and search the Java documentation but have not found anything even related to it. Could someone explain?
Inner classes, if any present in your class, will be compiled and the class file will be
ClassName$InnerClassName. In case of Anonymous inner classes, it will appear as numbers. Size of the Class (Java Code) doesn’t lead to generation of multiple classes.E.g. given this piece of code:
Classes which will be generated will be:
TestInnerOuterClass.classTestInnerOuterClass$TestInnerChild.classTestInnerOuterCasss$1.classUpdate:
Using anonymous class is not considered a bad practice ,it just depends on the usage.
Check this discussion on SO