How to get all annotations?
To obtains all annotations for classes, methods, constructors, fields or packages we use the
getAnnotations()method. This method returns an array of
In the following example we tried to read all annotations from the
sayHi method. First we need to obtain the method it self. Because the
sayHi has parameters we need to pass not only the method name to the
getMethod() method, we also need to pass the parameters type of the method.
getAnnotations() method will return only annotation that has a
RetentionPolicy.RUNTIME. Because other retention policy doesn't allow the annotation to available at runtime.