will java outer class compilation effects inner class

一曲冷凌霜 提交于 2019-12-01 04:44:00

问题


I need to give a patch to websphere. where I have a main java class which has three inner classes. I have few code changes to main class but no changes to any inner classes. Now my question is should I need to give all innerclasses along with main class file as a part of patch or main class alone sufficient?


回答1:


This is not an authoritative answer, but every time I did such patching, I copied all the classes (outer and inner classes), i.e.

Outer.class
Outer$1.class     // These indexes might change ...
Outer$2.class     // ... between compilation runs
Outer$Inner.class // This name should never change

When I didn't do this, there were usually some late classloading side-effects. In my opinion, this most often happened because of anonymous inner classes, which do not always re-generate the same "anonymous class index" (as in $1, $2, etc), depending on their order in the .java file.

So, to be sure, as this sort of patching is quite a hooligan technique anyway, I always copied all of the classes.




回答2:


Inner class is just like normal class with implicit reference to outer class so I would say it is safe to give only outer class if you really didn't change the inner ones.



来源:https://stackoverflow.com/questions/12915778/will-java-outer-class-compilation-effects-inner-class

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