O
Omega
I've been doing some research online about this subject and I've come
across a pretty even balance of "why I need to do it" and "why it
isn't possible".
I want to maybe get some discussion going, and maybe if there is
anyone out there to suggest some alternatives or the best method to
accomplish what I want.
What I've read so far is that:
1. Packages are not hierarchical, and stand separate to each other,
despite similarities.
2. Classes are not fetched until they are requested/needed.
Point 1 seems really irrelevant to my purpose as the way I've got my
program set up, I know the interface my class will implement (and thus
can use it as an instance of that interface), and I know the specific
package my classes will be found in - both at compile time. Java
offers reflection upon Packages, so they can't be totally redundant...
Point 2 is a good point and it is certainly the biggest reason why
this is not possible or not done yet: flexibility. But what happens
when you import an entire package? For example "javax.swing.*". I'm
not having an easy time discerning the behaviour, but wouldn't the
classloader reach over and ask for every class in the package? Or am
I mistaken, and the classloader only gets classes when they are first
interacted with?
At that point, even the functionality of getting the names of classes
only retrieved by the classloader within the package would suffice. I
could write my loaders for each type of runtime-discovered class to
request ".*" of the package and relax knowing I'm not requiring
everything in a .JAR to be loaded...?
IDEs like NetBeans, Eclipse and others do all kinds of wicked
reflection when you think about it. To what degree they cheat, I
don't know, and would love to!
To put my question or intention as simply as possible:
During run-time, how do I create one instance of each class in a
package when all I know at compile-time is the package's name?
across a pretty even balance of "why I need to do it" and "why it
isn't possible".
I want to maybe get some discussion going, and maybe if there is
anyone out there to suggest some alternatives or the best method to
accomplish what I want.
What I've read so far is that:
1. Packages are not hierarchical, and stand separate to each other,
despite similarities.
2. Classes are not fetched until they are requested/needed.
Point 1 seems really irrelevant to my purpose as the way I've got my
program set up, I know the interface my class will implement (and thus
can use it as an instance of that interface), and I know the specific
package my classes will be found in - both at compile time. Java
offers reflection upon Packages, so they can't be totally redundant...
Point 2 is a good point and it is certainly the biggest reason why
this is not possible or not done yet: flexibility. But what happens
when you import an entire package? For example "javax.swing.*". I'm
not having an easy time discerning the behaviour, but wouldn't the
classloader reach over and ask for every class in the package? Or am
I mistaken, and the classloader only gets classes when they are first
interacted with?
At that point, even the functionality of getting the names of classes
only retrieved by the classloader within the package would suffice. I
could write my loaders for each type of runtime-discovered class to
request ".*" of the package and relax knowing I'm not requiring
everything in a .JAR to be loaded...?
IDEs like NetBeans, Eclipse and others do all kinds of wicked
reflection when you think about it. To what degree they cheat, I
don't know, and would love to!
To put my question or intention as simply as possible:
During run-time, how do I create one instance of each class in a
package when all I know at compile-time is the package's name?