Here you can find the source of getAnnotation(Class> clazz, Class
Parameter | Description |
---|---|
clazz | The class to test contains the specified annotation . |
annotation | The annotation to check the specified class for. |
public static <T extends Annotation> Optional<T> getAnnotation(Class<?> clazz, Class<T> annotation)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.util.Optional; public class Main { /**//from w ww .j a v a 2 s.c om * Returns the specified {@link T annotation} for the potentially annotated {@link Class class} if * it exists. * * @param clazz The class to test contains the specified {@code annotation}. * @param annotation The annotation to check the specified {@code class} for. * @return The {@code annotation} if and only if it exists otherwise {@link Optional#empty()}. */ public static <T extends Annotation> Optional<T> getAnnotation(Class<?> clazz, Class<T> annotation) { return Optional.ofNullable(clazz.getAnnotation(annotation)); } }