Inspecting package annotations

Annotations specific to packages are added in package-info.java as in the following screenshot. Here, the modern.challenge package was annotated with the @Packt annotation:

A convenient solution to inspect the annotations of a package starts from one of its classes. For example, if, in this package (modern.challenge), we have the Melon class, then we can obtain all annotations of this package as follows:

Class<Melon> clazz = Melon.class;
Annotation[] pckgAnnotations = clazz.getPackage().getAnnotations();

Annotation[] printed via Arrays.toString() reveals a single result:

[@modern.challenge.Packt()]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.191.86