删除子类中的注释? [英] Remove Annotations in Subclass?

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

问题描述

我有一个需要注释的子类,该注释在父类中声明已删除.这样做的最佳方法是什么?

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.

这可能会对您的逻辑产生意想不到的结果,因为其他代码可能会依赖这些定义来做出运行时决策.

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天全站免登陆