Determining interface implementations during runtime ?

M

Marcus Crafter

Hi All,

Hope all is going well!

I was wondering if anyone had any ideas how I might be able to determine
reasonably efficiently what implementations of a given interface are
available within the current scope of available jars/classfiles during
runtime in my application?

Anyone done something like that before using reflection or similar?

Any ideas/etc appreciated.

Cheers,

Marcus

--
.....
,,$$$$$$$$$, Marcus Crafter
;$' '$$$$: Computer Systems Engineer
$: $$$$: ManageSoft Corporation
$ o_)$$$: Melbourne Australia
;$, _/\ &&:'
' /( &&&
\_&&&&'
&&&&.
&&&&&&&:
 
M

Mike Schilling

Marcus Crafter said:
Hi All,

Hope all is going well!

I was wondering if anyone had any ideas how I might be able to determine
reasonably efficiently what implementations of a given interface are
available within the current scope of available jars/classfiles during
runtime in my application?

Anyone done something like that before using reflection or similar?

Any ideas/etc appreciated.

There's no way to navigate from an interface to its implementers; you'd need
to
1. iterate through all of the classes, and
2. check which implement the interface.

For 2, use Class.isAssignableFrom(). Using Class.getInterfaces() will
omit classes whose superclass is an implementor but which don't declare
themselves as implementors.

1 cannot in general be done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top