How to get list of classes from a package
Thomas.Hawtin at Sun.COM
Mon Feb 16 17:29:42 UTC 2009
David M. Lloyd wrote:
> On 02/16/2009 10:22 AM, Ulf Zibis wrote:
>> can anybody tell me, how I could get al list or enumeration of the
>> classes, which belong to a package.
>> I can't see any appropriate method in java.lang.Package :-(
> This isn't really possible at run time, since one doesn't know whether a
> class exists until one tries to load it. The classloader might not even
> know. Also, a package can span classloaders, adding more complexity to
> the problem.
IIRC, you will get a different Package for each class loader, for a
given package name. Certainly classes with the same package name will
not have Java access to default/protected
members/classes/interface/constructors from different class loaders.
But yes, a list of classes is not necessarily complete. Also, IIRC,
Proxy dynamically inserts classes into packages as well.
More information about the core-libs-dev