开发者

Java Subclass $

I am new to Java and might be asking a basic question which might sound silly to some.

After I compile my Main Java class most of the subclasses are displayed as $ in the folder. I copy the complied 开发者_如何学编程classes and put it on another location to execute. Everytime I make make a change to the main class or one of the sub classes do I need to copy all the associated subclasses? or just copying the changed ones will do?

Thanks. Nick


Copying the changes will do.

Normally, you would let your IDE (e.g., Netbeans) / build system (e.g., Ant / Maven) do this for you. Alternatively you could create an executable jar-file, leaving you with only one file to copy.


Classnames containing $ are for nested/anonymous classes.

And see this Stackoverflow question.

But that's not the whole point. Quoting OP I copy the complied classes and put it on another location to execute. -- looks like you should automate this task and employ one of traditional Java build tools such as Ant or Maven.


Nick,

Are you referring to nested classes? If so, they will contain "$" in the compiled class file names. Assuming your code changes were only to the parent class, the nested class bytecode should not have changed during the recompilation. It should work to only copy the main .class file. However, it's obviously more of a guarantee to copy the everything.


Is this about subclassing (class Y extends X {}), or nested classes (class Y { class X {} })?

The $ that you mention seems to indicate the latter, in which case you should probably copy everything, but if you are only subclassing then just copying the compiled versions of the files you have changed is probably just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜