PAGE2GO2 HOME | INTERNET NEWS

LeighExchange - Free Advertising Network Stock Research at Internet Speed Need Money Easy and Quick?

Re: Reflection: Instantiate All Classes in a Package?

 List
Subject: Re: Reflection: Instantiate All Classes in a Package?
Poster: Jason Cavett
Date: 23 Mar 2007 14:35:02 -0700
Related Postings: 1 2 3 4 5
On Mar 23, 5:23 pm, Joshua Cranmer wrote:
> Jason Cavett wrote:
> > I was wondering...
>
> > Is it possible, by using Java reflection, to instantiate all classes
> > existing in a package without knowing the names of those classes. I'm
> > envisioning something like this (pseudocode):
>
> > Start my class
> > Class goes to package x
> > Package x contanis all the classes I need to instantiate
> > Using a (loop/something?) I loop through all the classes and
> > instantiate each one
>
> > To clarify what I'm trying to do, I am creatnig an error checking
> > application that relies on a series of rules that groups of developers
> > will code in Java (yeah, I realize I could have it in XML or something
> > that makes more sense, but I am the third or fourth developer to work
> > on this project). All the (compiled) classes are placed in a specific
> > package, but I never will know exactly which classes are there. I was
> > hoping for some way to discover and initialize them at runtime. (They
> > all implement the same interface, so that part is easy.)
>
> > Is this even possible? Is there a better solution? Thanks for any
> > clarification.
>
> Using Java reflection, the answer is NO. For more information, check the
> message thread "Getting a list of classes in a package"; there is a nice
> long discussion on class/package/reflection.
>
> P.S. it generally helps to search recent posts on Usenet before asking a
> question.- Hide quoted text -
>
> - Show quoted text -

My mistake. Thanks for pointing me to that thread.

 

Page2Go2.com is not responsible for content of this message.