In Java, there aren't general methods for enumerating classes by design. This is because classes could be loaded from anywhere, or dynamically created. Storing class files in a JAR or directory is just one of any possible class loaders.
So, while it might be more reasonable to assume that enclosed classes are a known, enumerable set, it doesn't make sense to provide a method that works only in that special case.
If you assume the common case of a URLClassLoader
, you can treat the underlying URLs as file systems and enumerate their contents. This might be appropriate if you are creating a tool to do something with existing third-party code, and it has even been adopted for many Java EE standards (mistakenly, I feel).
If you are creating a plug-in mechanism, providing metadata in a well-known location is more efficient, reliable, and works with any valid class loader.