- <p>package cyc.annotation1;
- public class Dmeo{
- @SuppressWarnings("unchecked")
- @Deprecated()
- @Override
- public String toString(){
- return "a cai" ;</p><p>}</p><p>}</p><p> </p><p>反射类:</p><div class="blockcode"><blockquote><p>package cyc.annotation1;
- import java.lang.annotation.Annotation;
- import java.lang.reflect.Method;
- public class ReflectAnnotationDemo {
- public static void main(String args[]) throws Exception{
- Class<?> c = null ;
- c = Class.forName("cyc.annotation1.Demo") ;//实例化Class
- Method me = c.getMethod("toString") ; //取得toString方法
- Annotation an[] = me.getAnnotations() ; //取得方法中的Annotation
- for(Annotation a:an){
- System.out.println(a) ;
- }
- }
- }
- </p><p>虽然没错,但是运行没结果,哪有错误???</p>
复制代码
|
|