Java Reference
In-Depth Information
public class App {
@Unfinished(message = "Make sure that this
element is not null")
String size;
public static void main(String[] args) {
System.out.println("Hello World
Although our annotation already looks like a standard annotation, it is not yet oper-
ational. For this, a class called processor must be available to the compiler. This
class will describe the action to take when an item is annotated with our custom an-
To achieve a custom processor for Java 6 annotation, we mainly need to implement
the process() methodofthe javax.annotation.processing.Processor in-
terface and define the annotations supported by this processor with the @Suppor-
tedAnnotationTypes annotation. The following code shows the processor of our
custom Unfinished annotation. As you can see, for the implementation of the
process() method, we used the abstract class AbstractProcessor that imple-
ments the Processor interface. (This prevents us from having to implement all the
methods defined in this interface.)
public class UnfinishedProcessor extends
AbstractProcessor {
* For the ServiceLoader
public UnfinishedProcessor() {
Search WWH ::

Custom Search