Menu

Implemented interfaces of a TypeDeclaration

Developers
smaol
2009-11-24
2012-10-08
  • smaol

    smaol - 2009-11-24

    Hi everybody,

    I was wondering if there's a method to retrieve just the implemented
    interfaces of a class - I know that they occur in the result-list of the
    getSupertypes()/getAllSupertypes() method of a TypeDeclaration together with
    the real/inheritance-based supertype(s), but is there also a seperate method
    for just getting the interfaces? Or can I assume that each occuring element in
    the result of getSupertypes() beside the first one is an interface?

    Thanks for your help!
    Steffen

     
  • Tobias Gutzmann

    Tobias Gutzmann - 2009-11-25

    Hej,

    you can assume that only for ClassDeclarations. There, the first item is
    always a class, the rest (if any) interfaces (java.lang.Object doesn't have
    any supertype at all, of course). For InterfaceDeclarations and
    AnnotationDeclarations, the last item is java.lang.Object. For
    EnumDeclarations, the first item is java.lang.Enum (well, a class), the other
    interfaces.

    A special case are TypeParameterDeclarations. A TypeParameterDeclaration's
    supertypes are those defined in the bounds. There, one class and many
    interfaces may be present. Recoder reports them in the same order as they are
    declared in the source code, e.g., for
    <T extends Serializable & AbstractList>
    the first item returned by getSupertypes() is an interface, the second a
    class.

    /Tobias

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.