SomeClass.java
import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; public class SomeClass { @SomeToken public void someMethod() { } /* * 这个可以放在拦截器中 * */ public static void main(String[] args) throws SecurityException, NoSuchMethodException { Method method = SomeClass.class.getMethod("someMethod", new Class<?>[] {}); if (null != method && method.isAnnotationPresent(SomeToken.class)) { // 如果这个方法被这个注解类注解,则可以做一些特殊处理 System.out.println(11); } } } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface SomeToken { }
标签:lang,反射,JAVA,java,public,annotation,method,import,Annotation From: https://www.cnblogs.com/zno2/p/6121311.html