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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…