Wednesday, April 25, 2012

How do Java method annotations work in conjunction with method overriding?

I have a parent class Parent and a child class Child, defined thus:



class Parent {
@MyAnnotation("hello")
void foo() {
// implementation irrelevant
}
}
class Child {
@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.





No comments:

Post a Comment