Determining interface implementations during runtime ?

Discussion in 'Java' started by Marcus Crafter, Feb 19, 2004.

  1. 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
    ;$, _/\ &&:'
    ' /( &&&
    \_&&&&'
    &&&&.
    &&&&&&&:
     
    Marcus Crafter, Feb 19, 2004
    #1
    1. Advertising

  2. "Marcus Crafter" <> wrote in message
    news:...
    > 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.
     
    Mike Schilling, Feb 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sparko

    Interface implementations

    Sparko, Mar 2, 2004, in forum: Java
    Replies:
    4
    Views:
    367
    Christophe Vanfleteren
    Mar 2, 2004
  2. Jim Cobban
    Replies:
    0
    Views:
    421
    Jim Cobban
    Nov 15, 2003
  3. z-man
    Replies:
    15
    Views:
    623
    Chris Uppal
    Oct 11, 2006
  4. Chris
    Replies:
    2
    Views:
    325
    Chris
    Mar 15, 2007
  5. Replies:
    11
    Views:
    545
Loading...

Share This Page