Java Subclass $

非 Y 不嫁゛ 提交于 2019-12-13 04:12:19

问题


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


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/5016668/java-subclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!