No, unfortunately, for the same reason why you cannot list ordinary classes in a package.
Inner classes are really ordinary classes at runtime. The compiler does some tweaking to get around normal access rules. For example, an inner class appears to be able to access the private fields and methods of the enclosing class β it can do this because the compiler creates a non-unit access function that is used by the inner class. See Java in a nutshell - how inner classes work for details.
Inner classes are regular classes, and they cannot be reliably listed, so a general answer is not possible.
However, it can be resolved in specific cases. If you know the JAR files that you use, you can yourpakage.YourClass$<something>.class over all the files in the JAR by looking for yourpakage.YourClass$<something>.class template files, where <something> is one or more characters.
EDIT: There are various types of inner class:
- declared elements such as interfaces and classes
- Anonymous classes and local classes
If you only care about the first case, then BalusC's answer using getDeclaredClasses is correct. If you want all the inner classes, then getDeclaredClasses , unfortunately, will not work. See Error SDN 4191731 . In this case, you can try one of the enumation methods of the class suggested in the link (for example, scanning a JAR file.)
source share