Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java reflection: How can I retrieve anonymous inner classes?

I have an anonymous inner class inside another class (SomeClass).

Both SomeClass.class.getClasses() and SomeClass.class.getDeclaredClasses() return empty arrays.

I couldn't find some hints on this in Class' Javadocs.

Can anonymous inner classes be retrieved using reflection in some way?

What else are notable differences between anonymous inner classes and normal inner classes?

like image 232
java.is.for.desktop Avatar asked Oct 15 '22 12:10

java.is.for.desktop


1 Answers

You could try a brute force search of Class$1 ... Class$n until you can't find any more.

like image 167
Peter Lawrey Avatar answered Oct 21 '22 05:10

Peter Lawrey