在子类中删除批注? [英] Remove Annotations in Subclass?

查看:104
本文介绍了在子类中删除批注?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子类,需要一个注解,即去掉父类中声明。什么是做到这一点的最好方法是什么?

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;

 }

,因为这有几个缺点(因为它包括垫层父成员= this.foobar可以不同,以super.foobar)...

as this has several disadvantages (as it "covers" the underlaying parent member = this.foobar can be different to super.foobar)...

1)是否有从子类(这里是儿童)父类删除注释的一种简单的方法?

1.) Is there an easy way of removing an annotation from a Parent Class in the Subclass (here Child)?

2)什么是清除在子类中的注释正式的方式?

2.) What is the official way to remove annotations in a Subclass?

非常感谢!马库斯

推荐答案

如果你想要做这样的事情可能比你应该再看看你的设计。

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.

这可以因为其他code你的逻辑意外的结果可能会依赖这些定义做出决定运行

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.

这篇关于在子类中删除批注?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆