J
Jason Cavett
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.
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.