April 2017
Beginner
504 pages
14h 11m
English
Annotations, as we saw, can have parameters. To declare these parameters in the @interface declaration of the annotation, we use methods. These methods have a name and a return value, but they should not have an argument. You may try to declare some parameters, but the Java compiler will be strict and will not compile your code.
The values can be defined at the place where the annotation is used, using the name of the method and with the = character, assigning to them some value that is compatible with the type of the method. For example, let's suppose that we modify the declaration of the annotation PoweredDevice to the following:
public @interface ParameteredPoweredDevice { String myParameter(); }
In such a case, ...
Read now
Unlock full access