java - Is it possible to omit some annotation attributes but not all? -
in java tutorials - annotations part, question 3 (https://docs.oracle.com/javase/tutorial/java/annotations/qande/questions.html), annotation expected used below:
@meal("breakfast", maindish="cereal")
i tried define annotation below not allow above usage.
public @interface meal { string value(); string maindish(); }
is possible omit first attribute name question suggested?
no, shortcut works if specify value
attribute , nothing else.
otherwise must explicitly write value=
, correct version @meal(value = "breakfast", maindish = "cereal")
Comments
Post a Comment