I've heard that Java bytecode actually doesn't support any kind of unnamed classes. How does javac translate unnamned classes to named ones?
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