> I would like to use reflection
Reflection is usually the wrong tool. Think twice before you use it.
E.g. if you do this so a superclass knows all its subclasses then you
probably have a design error and you should rethink your design.
But you have other problems, too.
> in someway to load all classes in a
> given package that implement an interface.
Since a package is open-ended you can't find all classes in a given
package. Please spare us the discussion of this fact. If you don't
believe it, read the Java spec. Without having all potential
candidates you can't find all classes in a given package that
implement a particular interface.
> I assume this is possible but the documentation isn't jumping out at
> me on how that's done.
It is not possible.
> Ideas anyone?
Modify your requirement. For example, all classes in a jar or a
directory to which you have the pathname. Or all classes from a (text)
list of class names.
Lew - 28 Aug 2007 22:14 GMT
Sideswipe wrote:
>> in someway to load all classes in a
>> given package that implement an interface.
> Since a package is open-ended you can't find all classes in a given
> package. Please spare us the discussion of this fact. If you don't
> believe it, read the Java spec. Without having all potential
> candidates you can't find all classes in a given package that
> implement a particular interface.
>> I assume this is possible but the documentation isn't jumping out at
>> me on how that's done.
> It is not possible.
To expound slightly more on Hunter's point, though as he says if you google
around the Usenet archives you will find quite a bit on this FAQ, new classes
can appear in a package any time. You'd have to run your search for infinite
time.
It's like making a dictionary of every word in the English language. The
language changes while you're compiling the list. You can never finish, Sisyphus.

Signature
Lew
Daniel Pitts - 29 Aug 2007 01:49 GMT
> Sideswipe wrote:
> >> in someway to load all classes in a
[quoted text clipped - 18 lines]
> --
> Lew
Often people think of this as a solution to the service provider
pattern. Java has a specification for providing service providers. I
suggest you look at it.
Sideswipe - 29 Aug 2007 18:01 GMT
I didn't realize this was such a FAQ. More search did turn up some
ideas. I also fully understand the English dictionary analogy. But,
even though that's true it doesn't stop people from printing
dictionaries. Which is what I was looking for.
Sideswipe - 29 Aug 2007 17:59 GMT
Generally I don't bother responding to a rude poster, but this time I
will.
I wasn't looking for the end-all be all list of classes implementing
an interface in a package. Only the ones at startup and currently in
the class loader.
I wasn't asking you to _judge_ my question and ponder what stupid
thing I might be cooking up either.
This post from sun shows a possibility:
http://forum.java.sun.com/thread.jspa?threadID=341935&start=15
I actually did want to limit the scope to only classes in the same
jar. Try to actually be a positive member of this community and show
how even a limited case could be done and what the caveats are.
-----------------
Perhaps a an interesting extension to ClassLoader would be to add a
listener method for every time a new class is loaded.
Andrew Thompson - 29 Aug 2007 18:40 GMT
...
>I wasn't looking ...
...
>I wasn't asking ...
Did you consider contracting a help-desk or consultant?*
Be sure to mention those conditions when signing up, so
they might charge the appropriate rate. This, OTOH, is
a discussion forum.
>...Try to actually be a positive member of this community
Try not to spit the dummy when someone pursues the
technical matter, or questions the entire strategy.
>...and show
>how even a limited case could be done and what the caveats are.
* This is not a help desk, in case you might have
any illusions.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
On Tue, 28 Aug 2007 17:52:27 -0000, Sideswipe
<christian.bongiorno@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>I would like to use reflection in someway to load all classes in a
>given package that implement an interface.
see http://mindprod.com/project/interfacefinder.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Andreas Leitgeb - 29 Aug 2007 11:06 GMT
> see http://mindprod.com/project/interfacefinder.html
While I understand that you do not give any free support
to takers of such a project, but I've got a bugreport
about the text there:
" 2.) Split it at the semicolons with Regex.split.
Semicolons? That's only on MsWindows-platform, so
rather than splitting at semicola, one should
*always* split paths at File.pathSeparator instead.