Inspecting annotations of the superclass

For inspecting the annotations of the superclass, we need to call the getAnnotatedSuperclass() method:

This method returns the superclass type that is annotated:

Class<Melon> clazz = Melon.class;
AnnotatedType superclassType = clazz.getAnnotatedSuperclass();

And let's get some information as well:

// modern.challenge.Cucurbitaceae
System.out.println("Superclass type: "
+ superclassType.getType().getTypeName());

// [@modern.challenge.Family()]
System.out.println("Annotations: "
+ Arrays.toString(superclassType.getDeclaredAnnotations()));

System.out.println("@Family annotation present: "
+ superclassType.isAnnotationPresent(Family.class)); // true
..................Content has been hidden....................

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