i have a child Class, that needs an Annotation, that is declared in the Parent class removed. What is the best way to do this?
public class Parent
@MyAnnoation
String foobar;
}
public class Child extends Parent {
//here I only want to remove the @MyAnnotation from String foobar;
}
What I want to avoid is, “overriding” the member
public class Child extends Parent {
String foobar;
}
as this has several disadvantages (as it “covers” the underlaying parent member = this.foobar can be different to super.foobar)…
1.) Is there an easy way of removing an annotation from a Parent Class in the Subclass (here Child)?
2.) What is the official way to remove annotations in a Subclass?
Thanks very much! Markus
If you want to do something like this than you probably should have another look at your design.
I think that if there is a way to remove a runtime annotation than that would not be recommended, because you would be remove a part of a class definition. Like removing a member access modifier for instance.
That can have unexpected results on your logic since other code might rely on these definitions to make runtime decisions.
If you need to modify a class definition during runtime than this class should probably not be defined in such a way in the first place.