I have a parent class Parent
and a child class Child
, defined thus:
class Parent {
@MyAnnotation("hello")
void foo() {
// implementation irrelevant
}
}
class Child extends Parent {
@Override
foo() {
// implementation irrelevant
}
}
If I obtain a Method
reference to Child::foo
, will childFoo.getAnnotation(MyAnnotation.class)
give me @MyAnnotation
? Or will it be null
?
I'm interested more generally in how or whether annotation works with Java inheritance.
Best Answer
Copied verbatim from http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations.html#annotation-inheritance: