I've heard that Java bytecode actually doesn't support any kind of unnamed classes. How does javac translate unnamned classes to named ones?
Asked
Active
Viewed 2,524 times
1 Answers
26
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.

erickson
- 265,237
- 58
- 395
- 493
-
5`$` is a valid character, but it's not recommended to use it in user-defined names. – axtavt Apr 27 '11 at 18:08
-
1You can easily see this when you compile a class with anonymous inner classes, because you get multiple `*.class` files, with names like `EnclosingClass$n.class`. – Jesper Apr 27 '11 at 18:25
-
Does the counter start from 0 or from 1. And is it continuously numbered from top to bottom of a source file? – johsin18 Mar 07 '14 at 16:15