首页 > 编程知识 正文

eclipse批量注释,java单行注释和多行注释

时间:2023-05-04 23:10:00 阅读:147833 作者:2215

小典

只是没有误会。 请与java.lang.annotation.Inherited联系。 这是评论的评论。 这意味着,被注释的类的子类将被视为具有与父类相同的注释。

范例

考虑以下两个评论。

@Inherited

@target(elementtype.type ) )。

@ retention (retention policy.runtime ) )。

公共@ interfaceinheritedannotationtype {

}

@target(elementtype.type ) )。

@ retention (retention policy.runtime ) )。

公共@ interfaceuninheritedannotationtype {

}

如果这样评论了三个类:

@UninheritedAnnotationType

class A {

}

@InheritedAnnotationType

class B extends A {

}

类c extends b {

}

执行此代码

system.out.println (newa (.getclass ).get annotation (inheritedannotationtype.class ) );

system.out.println (newb (.getclass ).get annotation (inheritedannotationtype.class ) );

system.out.println (newc (.getclass ).get annotation (inheritedannotationtype.class ) );

system.out.println (_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

system.out.println (newa (.getclass ).get annotation (uninheritedannotationtype.class ) );

system.out.println (newb (.getclass ).get annotation (uninheritedannotationtype.class ) );

system.out.println (newc (.getclass ).get annotation (uninheritedannotationtype.class ) );

这样的结果会被打印出来。 取决于注释的包。

空值

@InheritedAnnotationType () )

@InheritedAnnotationType () )

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ u

@UninheritedAnnotationType ()

空值

空值

正如您所看到的,UninheritedAnnotationType不能继承,但C继承注释InheritedAnnotationType来自b。

我不知道和这个有什么关系。

2020-10-18

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。