Java annotation入门:http://www.blogjava.net/ericwang/archive/2005/12/13/23743.html
Java annotation 手册: http://www.blogjava.net/mlh123caoer/archive/2007/09/06/143260.html
Java annotation 高级应用: http://www.blogjava.net/wuxufeng8080/articles/93046.html
package org.airlinkmatrix.sample;
import java.lang.reflect.Method;
import org.airlinkmatrix.sample.annotation.IsWired;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@IsWired
public class TestAnnotation {
static private Log log = LogFactory.getLog(TestAnnotation.class);
@IsWired(kidding="are you crazy?")
private void wired(){
}
@IsWired public void wired1(int k){
}
public static void main(String[] args) {
Class clazz = TestAnnotation.class;
if (clazz.isAnnotationPresent(IsWired.class)){
log.info("class is wired!");
}
try {
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(IsWired.class)){
log.info("the method " + method.getName() +
" is wired!!");
}else{
log.info("the method " + method.getName() +
" is not wired!!");
}
}
} catch (SecurityException e) {
e.printStackTrace();
}
}
}
import java.lang.annotation.RetentionPolicy;
public @interface IsWired {
public String kidding() default "";
}
TestAnnotation - the method wired1 is wired!!
TestAnnotation - the method main is not wired!!
TestAnnotation - the method hashCode is not wired!!
TestAnnotation - the method getClass is not wired!!
TestAnnotation - the method wait is not wired!!
TestAnnotation - the method wait is not wired!!
TestAnnotation - the method wait is not wired!!
TestAnnotation - the method equals is not wired!!
TestAnnotation - the method notify is not wired!!
TestAnnotation - the method notifyAll is not wired!!
TestAnnotation - the method toString is not wired!!