Determining interface implementations during runtime ?  
Author Message
Marcus Crafter





PostPosted: 2004-2-19 14:54:00 Top

java-programmer, Determining interface implementations during runtime ? 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
;$, _/\ &&:'
' /( &&&
\_&&&&'
&&&&.
&&&&&&&:
 
Mike Schilling





PostPosted: 2004-2-20 7:31:00 Top

java-programmer >> Determining interface implementations during runtime ?
"Marcus Crafter" <email***@***.com> wrote in message
news:email***@***.com...
> 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.