读书人

java 引语代码

发布时间: 2012-11-12 12:31:58 作者: rapoo

java 注解代码

package com.endual.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class MyRefection {
??
??? public static void main(String args[]) throws SecurityException, Exception{
??? ??? Class<HelloM> c = HelloM.class;
??? ??? HelloM m = new HelloM();
??? Method method = c.getMethod("sayHello", new Class[]{});
???
??? if(method.isAnnotationPresent(MyAnnotation.class)){
??? ??? method.invoke(m, new Object[]{});
??? ??? MyAnnotation annotation = method.getAnnotation(MyAnnotation.class);
??? ???
???????? String hello1 = annotation.value();
//?????? String hello = annotation.annotationType().getName();
//??????
?????? System.out.print(hello1);
??? }
? }
}

读书人网 >编程

热点推荐