Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'value' a java keyword?

It seems to have a special meaning in annotations - it allows you to skip the parameter names when instaniating an annotation.

@Foo(bar = "abc") // a normal instantiation of an annotation
@Foo("abc") // if bar were renamed 'value'

Where is this documented? Is value a keyword or not? See also.

like image 866
ripper234 Avatar asked Jul 04 '11 12:07

ripper234


1 Answers

It's not a regular keyword, as it's not listed in section 3.9 of the JLS. In particular, you can use it as an identifier anywhere you like, as far as I'm aware.

The use of value by default for an annotation value is specified in section 9.7:

The third form of annotation, single-element annotation, is a shorthand designed for use with single-element annotation types:

SingleElementAnnotation:
   @ TypeName ( ElementValue )

It is shorthand for the normal annotation:

   @TypeName ( value = ElementValue )
like image 77
Jon Skeet Avatar answered Sep 27 '22 23:09

Jon Skeet