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

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

Similar Messages

  • Where are the implementations for some interfaces in the search_sdk.jar?

    Hi,
    Is the source code for the implementation of some interfaces (DocumentMetadata etc) available to public?
    Thanks.
    Jun
    Message was edited by:
    Alwaysthink

    Source code is not available. The javadoc is distributed with the installation media. On my machine I can find the javadoc for DocumentMetadata here:
    file:///F:/SES_1018_WIN32_DVD2/doc/search.1018/b32260/toc.htm

  • Why the HashMap implements the Map interface twice

    See the type hierarchy below:
    HashMap<K,V>
    &#9475;
    &#9507;AbstractMap<K,V>
    &#9475;&#9475;
    &#9475;&#9495;Map<K,V>
    &#9495;Map<K,V>
    The HashMap extends AbstractMap, which implements Map. So the HashMap has already implements Map, and has the Map type. But the HashMap's declaration still contains "implements Map".
    So why the HashMap implements the Map interface twice?
    Thanks in advance.

    georgemc wrote:
    Maybe the guy who wrote HashMap wanted to make it clear that HashMap implemented Map, rather than rely on you looking further up the hierarchy to find outYes, it does make the Javadoc clearer. If they hadn't done that then there would have been legions of newbies who couldn't tell that HashMap implemented Map and thousands of "I have a doubt, does HashMap implement Map" questions here.

  • The XElement class explicitly implements the IXmlISerializable interface?

    I see a sentence on a training book.
    "The XElement class explicitly implements the IXmlSerializable
    interface, which contains the GetSchema, ReadXml, and
    WriteXml methods so this object can be serialized."
    I don't understand it. From
    the example, explicitly implements the IXmlSerializable interface is from a custom class rather than XElement class. Is
    MSDN wrong?

    I mean in the stackoverflow example,the class is a customized one "MyCalendar:IXmlSerializable"
    public class MyCalendar : IXmlSerializable
    private string _name;
    private bool _enabled;
    private Color _color;
    private List<MyEvent> _events = new List<MyEvent>();
    public XmlSchema GetSchema() { return null; }
    public void ReadXml(XmlReader reader)
    If XElement is a class that implements IXmlSerializable, what is the detail then?
    public class XElement : IXmlSerializable
    public XmlSchema GetSchema() { *detail*?; }
    public void ReadXml(XmlReader reader){*detail*?}
    Any source code of XElement class?

  • Implementing two generic interfaces

    I have a generic interface,
    public interface Callback<R> {
       void result(R r);
    }Now I want to implement two Callback interfaces, like this
    class X implements Callback<Type1>, Callback<Type2> {
       public void result(Type1 r) {};
       public void result(Type2 r) {};
    }But Eclipse tells me "The interface Callback cannot be implemented more than once with different arguments".
    I don't see the reason why really. The two overloaded result methods have different signatures so there shouldn't be any problem in resolving the correct one based on parameter type in principle.
    Does anybody know the reason for this restriction or is it maybe an issue with Eclipse. I'm using Eclipse 3.2M5a and Java 6.0 beta.

    mlk has the correct answer, but here's some more explanation:
    Generics are only used at compile time. The actual bytecode specifies the base object type (aka type erasure), in this case Object. When you implement a generified interface, the compiler will generate a bridge method from the erased type to the specific type.
    Some examples should make this clearer.
    First, your interface. If you run javap on the compiled class, you'll see that it only defines a single method, "void result(Object)".
    Code that invokes the interface, like this:
        Callback<String> foo = \\
        foo.result("bar");also gets translated to a call on the base type. As far as the compiled class is concerned, there is no type safety. However, the compiler will complain if you pass something other than a String.
    The implementation class is where things get interesting:
    public class TestCallback implements Callback<String> {
      public void result(String x) {
    }If you run javap on this class, you'll see that it contains two implementations of result(): one that takes a String, and one that takes an Object. If you look at the bytecode, the latter performs a cast on the Object and invokes the String variant.

  • Implement an business interface in a bean

    Is it true that when specifing a number of business interfaces for a bean class with an annotation (@Remote) it not require that the bean class implement the interfaces ??
    it sounds weird to me..
    if it is possible , then where is the implementation of the interfaces?
    thanks in advanced.

    If your bean doesn't implement the business interface, you'll need to use annotations (@Remote on the session bean class) or the deployment descriptor to let the container know what the business interfaces are used by the session bean.
    For example,
    // BusinessIF1.java
    package myejbs;
    public interface BusinessIF1 { public void doSomething(); }
    // BusinessIF2.java
    package myejbs;
    public interface BusinessIF2 { public void doSomethingElse{}; }
    // MySessionBean.java
    package myejbs;
    @Remote({BusinessIF1.class, BusinessIF2.class})
    @Stateless
    public class MySessionBean {
    public void doSomething();
    public void doSomethingElse();
    }This isn't recommended, though. You'll lose a compile-time check to make sure that all of your business methods are implemented. You can catch this if you use Sun's verifier tool, though.

  • Does not implement the NamespaceHandler interface

    I depoly a war file and get following errors. This project does not contain jar files related with spring.
    BUILD FAILED
    weblogic.Deployer$DeployerException: weblogic.deploy.api.tools.deployer.DeployerException: Task 0 failed: [Deployer:149026]deploy application smap.war on AdminServer.
    Target state: deploy failed on Server AdminServer
    java.lang.IllegalArgumentException: Class [org.springframework.scripting.config.LangNamespaceHandler] does not implement the NamespaceHandler interface
         at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:119)
         at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96)
         at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:83)
         at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:498)
         at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:487)
         at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468)
         at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363)

    Hi,
    I am not sure - given the information you provide - that you posted to the right forum
    Frank

  • EJB3 Stateful Sessionbean how to implement multi business interfaces?

    Hi All,
    I met up some issue, can't make the session bean implement 2 business interfaces? Please kindly throw me some light! thanks
    Business sessionbean
    @Stateful
    @ConversationScoped
    @Named
    @Local( { IWizard.class, IRegisterWizard.class })
    public class RegisterWizard extends WizardBean {
    @Local
    public interface IWizard extends Serializable {
            public String back();
            public boolean hasBack();
            public boolean hasNext();
            public String next();
            public String abort();
    @Local
    public interface IRegisterWizard{
            public String submit();
    }error message of glassfish3 below:
    Caused by: java.lang.IllegalArgumentException: Not enough type information to resolve ejb for  ejb name class wizard.RegisterWizard
            at org.glassfish.weld.services.EjbServicesImpl.resolveEjb(EjbServicesImpl.java:121)
            at org.jboss.weld.bean.SessionBean.createReference(SessionBean.java:422)
            at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.<init>(EnterpriseBeanProxyMethodHandler.java:76)
            at org.jboss.weld.bean.SessionBean.create(SessionBean.java:298)
            ... 53 more

    There does appear to be a bug in the handling of the bean with multiple business interfaces. I filed an issue for it :
    https://glassfish.dev.java.net/issues/show_bug.cgi?id=11826. The inheritance is a separate issue. Are you getting the same error or a different one after applying @LocalBean.

  • How to name implementation of an interface

    Hi there
    is there any standard for naming concrete implementation of interfaces?
    So if I have an interface
    A
    in package "interfaces"
    is it sensful to call the concrete implementation of the interface interfaces.A A, too?
    class A implements interfaces.A{
    }? Or should it be called ConcreteA, or or or....?
    Thx for your tips.
    Sincerely
    Karlheinz Toni

    JebeDiAH heres a very interesting reading.
    Class and Interface Names
    Class names are always nouns, not verbs. Avoid making a noun out of a verb, example DividerClass. If you are having difficulty naming a class then perhaps it is a bad class.
    Interface names should always be an adjective (wherever possible) describing the enforced behaviors of the class (noun). Preferably, said adjective should end in "able" following an emerging preference in Java. i.e. Clonable, Versionable, Taggable, etc.
    Class, and interface names begin with an uppercase letter, and shoule not be pluralized unless it is a collection class (see below).
        Acceptable:
            class FoodItem
            interface Digestable
        UnAcceptable:
            class fooditem
            class Crackers
            interface Eat
    Naming collection classes (in the generic sense of collection) can be tricky with respect to pluralization. In general each collection should be identified as a plural item, but not redundantly so. If you are a collection type as part of the class name (List, Map, etc.) it is not necessary to use the plural form in the class name. If you are not using the collection type in the name it is necessary to pluralize the name. If you are extending one of the java colletction class (Map, HashMap, List, ArrayList, Collection, etc.) it is good practice to use the name of the collection type in the class name.    
        Acceptable:
            class FoodItems extends Object
            class FoodItemList extends ArrayList
            class FoodItemMap extends HashMap
        UnAcceptable:
            class FoodItem extends ArrayList
            class FoodItemsList extends ArrayList
    Class names should be descriptive in nature without implying implementation. The internal implementation of an object should be encapsulated and not visible outside the object. Since implementation can change, to imply implementation in the name forces the class name and all references to it to change or else the code can become misleading.
        Acceptable:
            AbstractManagedPanel
            LayeredPanel
        UnAcceptable:
            PanelLayerArray
    When using multiple words in a class name, the words should be concatenated with no separating characters between them. The first letter of each word should be capitalized.
        Acceptable:
            InverntoryItem
        UnAcceptable:
            Inverntory_item
            Inventoryitem
    Other than prefixes, no abbreviations should be used unless it is a well known abbreviation.
        Acceptable:
            CD=Compact Disc
            US=United States
        UnAcceptable:
            Cust=Customer
            DLR=Dealer
    I found it at http://www.iwombat.com/standards/JavaStyleGuide.html

  • Implementing the Serializable interface

    Hi guys,
    I have a conceptual question about implementing the Serializable interface - since it's only a marker interface (i.e. - it doesn't have any abstract methods) why does Java demand an object to implement this interface in order to be written into a file? What I'm asking is why wouldn't they make the writeObject method's signature
    public void writeObject(*Object* o)
    so any object can get in? What is the point of forcing a class to implement an interface in order to enable it to be written to a file?

    So that serialization requires the explicit consent of the class or superclass/superinterface.

  • Passing implementation of Java interfaces

    Hi
    I have a static function which I want to be supplied with a another class. Now the passed class needs to be an implementation of that class. How can I make sure?
    Thanks
    Saaransh

    an example:
    Lets say I have an interface :
    public interface foo
    //some methods
    Now thers a static function. Which I want should take in a parameter (an object) which has implemented the above interface.
    How do i do this?
    NOTE: I am making a framework API and thus the class making the object will not be known to me. It will be created by someone else and not me.
    Thanks

  • Implementation of the interface IF_EX_XSS_TIM_PER_INTERFACE.

    Dear Guru's,
    I need an example of implementation of the interface IF_EX_XSS_TIM_PER_INTERFACE.
    for methods
    -PROVIDE_OVERVIEW_LINE
    -PROVIDE_DROPDOWN_ENTRIES
    -PROVIDE_OVERVIEWTAB_FIELDCAT
    -PROVIDE_PERIOD_TABLE
    la idea es poder configurar la seleccion de periodos.
    regards.
    icemanirc
    Edited by: Juan Carlos De La Fuente Fuentes on Jul 12, 2011 11:08 PM

    excellent, now I can understand how to implement it.
    thanks
    Yugandhar Reddy

  • Cann't extend a inner class where as can Implement a nested Interface

    i cann't extend a inner class in some other outer class . Where as i can implement the nested Interface in some other class. Why????
    for example:-
    class ABC
    class Inner
    /* class body */
    interface TempInterface
    /* interfacebody */
    class OuterClass
    class InnerTwo extends ABC.inner //(line 1)Will give error
    class InnerTwo implements ABC.TempInterface //(line 2)Will run fine
    the line 1 is going to give compilation error i.e not in the scope but the line 2 will run fine .
    Both of the things are in the same class but giving 2 other results.
    I am not getting sufficient reasons for it.
    Can any one help me????
    Reagrds
    Arunabh

    As far as the language is concerned, the classonly
    exists in the context of an instance of theenclosing
    class.This still exhibits a class/object confusion to me.
    It should be 'instance only exists ...' or 'instance
    can only exist'. The class only exists in the
    scope of the enclosing class, but this is another
    issue.I'm not following what you're saying. The second sentence sounds like you're disagreeing with me. The last sentence sounds like you're agreeing with me.
    A non-static nested class is an instance member, just like an instance method or instance variable. As such, as far as the language is concerned, that class only exists in the context of an instance of the enlcosing class.It's not just instances of the nested class--its the class definition itself that only exists within the context of an instance of the enclosing class. That's why you have to do anEclosingIntstance.NestedClass and can't do EnclosingClass.NestedClass.

  • Why the ArrayList implements the List interface

    Why the ArrayList implements the List interface even though it extends the AbstractList class. Is it only for clarity of interface implemented?

    899440 wrote:
    Why the ArrayList implements the List interface even though it extends the AbstractList class. Is it only for clarity of interface implemented?I dont think there's any specific reason for that. In my opinion its redundant. May be its added for clarity so that from the documentation its obivous that ArrayList implements List.
    May be there's something which I am missing regarding this?

  • How to find classes implementing a certain interface at runtime

    I am making an Application and I want have a plug-in nature for the different tools I have.
    My App is packaged in a package with subpackages for the individual tools. I want to beable to remove/add subpackages without crashing the app.
    The only way I can see this working is for the App to search its sub packages for a certain interface (eg an 'AddOnTool' interface) and build a set of available AddOnTools.
    I just dont know if this is possible, but pretty sure it must be!....
    Once I have the set of available AddOnTools I also realise that I have to Construct the one chosen, this I see as my other hurdle!
    If I can be helped with these I'll be mighty Happy!

    You can use getClassLoader() in the Class class to get the ClassLoader, then use getPackages() to get an array of all packages available to your class. How to get a list of all classes, however, I can't find in the documentation; perhaps you can do more research.

Maybe you are looking for