How can I do Java annotation like @name("Luke") with no attribute inside parenthesis?

Lucas Batistussi picture Lucas Batistussi · Aug 2, 2012 · Viewed 23.9k times · Source

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")

Answer

pb2q picture pb2q · Aug 2, 2012

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

@interface CustomAnnotation
{
    String value();
}

This can be used like so:

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