本文介绍了如何在括号内没有属性的情况下进行像 @name("Luke") 这样的 Java 注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在括号内没有属性名称的情况下进行自定义 Java 注释?
How I can do custom Java annotation with no attribute name inside parentheses?
我不想要这个:@annotation_name(att=valor)
.我只想像在 Servlets 中一样,即:
I don't want this: @annotation_name(att=valor)
. I just want like in Servlets, i.e:
@WebServlet("/main")
推荐答案
定义一个名为value
的属性的注解,那么属性name可以省略:>
Define the annotation with an attribute named value
, then the attribute name can be omitted:
@interface CustomAnnotation
{
String value();
}
可以这样使用:
@CustomAnnotation("/main")
// ...
这篇关于如何在括号内没有属性的情况下进行像 @name("Luke") 这样的 Java 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!