Created
December 27, 2013 06:09
-
-
Save xudifsd/8143210 to your computer and use it in GitHub Desktop.
annotation的使用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
import java.lang.NoSuchMethodException; | |
public class T { | |
public static void main(String[] args) throws Exception { | |
executeWithAnnotationSupport(T.class, "doSomething"); | |
} | |
@InProgress | |
public static void doSomething() { | |
} | |
public static void executeWithAnnotationSupport(Class<?> clazz, String methodName) throws Exception { | |
Method[] ms = clazz.getMethods(); | |
for (Method m : ms) { | |
if (m.getName().equals(methodName)) { | |
InProgress inProgress = m.getAnnotation(InProgress.class); | |
if (inProgress != null) { | |
System.out.format("method '%s' for class '%s' is still work in progress\n", methodName, clazz.getName()); | |
} | |
} | |
} | |
} | |
} | |
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
@interface InProgress { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment