Using reflection
Now that you have learnt how to declare annotations and how to attach them to classes and methods, we can return to our ProductInformation class. Recall that we wanted to specify the type of products in this class and that each product type is represented by an @interface annotation. We have already listed it in the previous few pages, the one we will implement in our @PoweredDevice example. We will develop the code assuming that later there will be many such annotations, product types, and consistency checkers that are annotated with @Component and with one or more of our annotations.
Getting annotations
We will extend the ProductInformation class with the following field:
private List<Class<? extends Annotation>> check;
Since this is a DTO, and Spring needs the setters and getters, we will also add a new getter and setter to it. This field will contain the list of classes that each class implement one of our annotations and also the built-in JDK interface, Annotation...