Java Reflection Java Java API
java.lang.reflect.Method
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
Returns true if an annotation for the specified type is present on this element, else false.
package com.logicbig.example.method;import java.lang.reflect.Method;public class IsAnnotationPresentExample { private static class Test { @Deprecated private void process() { } private void init() {} } public static void main(String... args) throws NoSuchMethodException { Method m = Test.class.getDeclaredMethod("process"); boolean b = m.isAnnotationPresent(Deprecated.class); System.out.println(b); Method m2 = Test.class.getDeclaredMethod("init"); boolean b2 = m2.isAnnotationPresent(Deprecated.class); System.out.println(b2); }}
truefalse