Reputation: 141
I have a class with name StreamGo. It has 4 more class files with the same name like - StreamGo$1, StreamGo$2 etc. All these class files have different set of code. How do I merge them? And why does these class files get created with $1 and $2 etc?
Please help.
Upvotes: 0
Views: 236
Reputation: 9914
If there is an inner class in your java file, then the compiler will create a class file with name of Java file along with $. You cannot combine these class files. But if you are copying these class files, make sure you are copying all the class files starting with $ symbol! else it will not work
Upvotes: 1
Reputation: 183341
Those class files are automatically generated for anonymous inner classes defined inside StreamGo.java
. For example, if you have something like this:
final Runnable runnable = new Runnable() {
public void run() {
// ...
}
};
then you'll have a StreamGo$1.class
for the anonymous implementation of Runnable
that you've defined here.
Named nested classes will do much the same, except that you'll get their names instead of the number part.
Upvotes: 2
Reputation: 887459
These are compiler-generated classes for anonymous classes that you create in your class.
Since Java bytecode requires a separate .class
file for each class, you cannot merge them.
You may want to put all of your .class
files into a .jar
.
Upvotes: 1