与在括号内没有属性我可怎么办Java注释像@name(QUOT;卢克&QUOT)? [英] How I can do java annotation like @name("Luke") with no attribute inside parenthesis?
本文介绍了与在括号内没有属性我可怎么办Java注释像@name(QUOT;卢克&QUOT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该怎么办定制Java注释与括号内的无属性名称?
我不希望这样的: @annotation_name(ATT =勇武)
。我只是想喜欢Servlet中,即:
@WebServlet(/主)
解决方案
定义的注释名为单一属性值
,那么该属性的名称可以省略:
@interface CustomAnnotation
{
字符串值();
}
这可以用于像这样:
@CustomAnnotation(/主)
// ...
How I can do custom java annotation with no attribute name inside parentheses?
I don't want this: @annotation_name(att=valor)
. I just want like in Servlets, i.e:
@WebServlet("/main")
解决方案
Define the annotation with a single attribute named value
, then the attribute name can be omitted:
@interface CustomAnnotation
{
String value();
}
This can be used like so:
@CustomAnnotation("/main")
// ...
这篇关于与在括号内没有属性我可怎么办Java注释像@name(QUOT;卢克&QUOT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文