如何在Java中编译匿名类? [英] How are anonymous classes compiled in Java?
本文介绍了如何在Java中编译匿名类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我听说Java字节码实际上不支持任何类型的未命名类。 javac如何将未定义的类转换为命名的类?
I've heard that Java bytecode actually doesn't support any kind of unnamed classes. How does javac translate unnamned classes to named ones?
推荐答案
它合成形式的名称 EnclosingClass $ n
,其中n是 EnclosingClass
中的匿名类的计数器。因为不鼓励在标识符中使用 $
,这些名称不应与任何用户指定的名称冲突。
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.
这篇关于如何在Java中编译匿名类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文