[annotations][reflection] getting the annotation of the "super.method"

Discussion in 'Java' started by Ingo R. Homann, Jul 26, 2005.

  1. Hi,

    consider the following design:

    @interface MyAnnot {}

    class Sup {
    @MyAnnot void foo() {...}
    }

    class Sub {
    @Overrides void foo() {...}
    }

    Using reflection, i am accessing the method Sub#foo. Is there a *simple*
    possibility to find out that the 'original' method (Sup#foo) was
    annotated with @MyAnnot?

    I thought, that getAnnotations() vs. getDeclaredAnnotations() would do
    the job (like Class#getMethods() vs. getDeclaredMethods()), and that
    java.lang.annotation Type Inherited could help. But I understand the
    doku to this meta annotation, that this only works, if a class (rather
    than a method) is annotated (my test indicate that it does not work the
    way I want to).

    Did I understand that correctly?
    Why is this the case?
    Is there a reasonable eh reason for this 'asymetric', limited design
    that sun chose?
    What is the alternative?
    Is (*) the only solution?

    Ciao,
    Ingo

    (*) to recurse over all supertypes of the class (which is not really
    comfortable with reflection, because I would have to recursively check
    all implementing interfaces, the super class and all its interfaces, and
    all super interfaces of the interfaces), check if there is a method with
    the same signature and then check if this method has the annotation I am
    looking for.
    Ingo R. Homann, Jul 26, 2005
    #1
    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. Raymond McCrae
    Replies:
    2
    Views:
    1,494
    Raymond McCrae
    Mar 3, 2004
  2. pek
    Replies:
    2
    Views:
    1,071
  3. zweibieren

    A need for super.super.method()

    zweibieren, May 7, 2009, in forum: Java
    Replies:
    0
    Views:
    449
    zweibieren
    May 7, 2009
  4. Tom Anderson
    Replies:
    1
    Views:
    327
    Tom Anderson
    May 10, 2009
  5. grz01
    Replies:
    4
    Views:
    1,138
    Daniel Pitts
    Sep 28, 2009
Loading...

Share This Page