Hint: the debugger somehow knows what classes are. So you can too!
Try using javap in this example with two anonymous classes:
import java.util.*; public class Test { public static void main(String [] args) { Map m = new HashMap(){{System.out.print(1);}}; Map m1 = new HashMap(){{System.out.print(2);}}; } }
Compile it and run javap -c -l :
$ javap -c -l Test Compiled from "Test.java" public class Test extends java.lang.Object{ public Test(); Code: 0: aload_0 1: invokespecial
As you can see, the first class received the name Test$1 , the second - Test$2 . Hope that helps.
For more information, decompile the classes you are interested in, for example. javap -c -l Test\$2 . Pay attention to line numbers: they will give you a hint about where the class was defined in the source file.
alf
source share