如何在@括号(" Luke")之类的java注释中使用括号内没有属性? [英] How can I do java annotation like @name("Luke") with no attribute inside parenthesis?

查看:173
本文介绍了如何在@括号(" Luke")之类的java注释中使用括号内没有属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在括号内没有属性名称的自定义java注释?

How I can do custom java annotation with no attribute name inside parentheses?

我不希望这样: @annotation_name(att =英勇)。我只想在Servlets中,即:

I don't want this: @annotation_name(att=valor). I just want like in Servlets, i.e:

@WebServlet("/main")


推荐答案

使用名为的值,然后可以省略属性 name

Define the annotation with an attribute named value, then the attribute name can be omitted:

@interface CustomAnnotation
{
    String value();
}

这可以这样使用:

@CustomAnnotation("/main")
// ...

这篇关于如何在@括号(" Luke")之类的java注释中使用括号内没有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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