How are anonymous classes compiled in Java?

冷暖自知 提交于 2019-12-06 18:59:53

问题


I've heard that Java bytecode actually doesn't support any kind of unnamed classes. How does javac translate unnamned classes to named ones?


回答1:


It synthesizes a name of the form EnclosingClass$n, where "n" is a counter for anonymous classes in EnclosingClass. Because using $ in identifiers is discouraged, these names should not collide with any user-specified names.



来源:https://stackoverflow.com/questions/5808492/how-are-anonymous-classes-compiled-in-java

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