finding implementations of an interface programmatically

Hi... would anyone know how to find programmatically all classes that implement an interface?

Ideally, I would like to query on an interface and end up with a list of Class objects (i.e. the implementations of said interface).

Thanks

:)

Message was edited by:

javaBoy

[305 byte] By [javaBoya] at [2007-11-26 12:23:02]
# 1
This is asked about 38 times a week on these forums: Try a search :o)~D
aconst_nulla at 2007-7-7 15:22:28 > top of Java-index,Core,Core APIs...
# 2
can't be done. this gets asked all the time, and it's impossible.
georgemca at 2007-7-7 15:22:28 > top of Java-index,Core,Core APIs...
# 3

>can't be done. this gets asked all the time, and it's impossible.

Yes - technically correct.

However, in many contexts where you know what classloaders are at play (and lets face it, many of us do work on projects where we use known classloaders, and dont have some random loading off the net on demand going on), it is possible, useful, and very much do-able - if you accept the limitations and constraints.

So, OP, do a search and you'll probably find something useful to you.

~D

aconst_nulla at 2007-7-7 15:22:28 > top of Java-index,Core,Core APIs...
# 4

You search for Interface in any of the java files under the project like in eclipse search you have rebuild that

1. programmatically searching all the folders in the application for interface name in the implements clause of any java file

2. List all the names of the class which are matching the above

We need to write code for the 1.

Regards

R. Prasanna

ReadingExcela at 2007-7-7 15:22:28 > top of Java-index,Core,Core APIs...
# 5
If you are using java 6, java.util.ServiceLoader may be helpful.
jasonxa at 2007-7-7 15:22:28 > top of Java-index,Core,Core APIs...