天天v5洗澡 天天v5洗澡
穷矮丑。。。
关注数: 9 粉丝数: 22 发帖数: 1,238 关注贴吧数: 9
帮看看是什么问题。。。 这个程序由三个小的代码构成我都发上来,那位师兄师姐 告诉我怎么回事。报错了。 package com.wang.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface test { } 这个是自己定义的注解 package com.wang.Annotation; public class DoSometing { public void method1() { System.out.println("method1()"); } @test public void method2() { System.out.println("method2()"); } @test public int add(int a , int b ) { return a + b; } @test public void dosometing2() { System.out.println("dosometing2()"); } public static void main(String[] args) { System.out.println(DoSometing.class.getName()); } } 这个是需要进行测试方法的类 package Constent; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import com.wang.Annotation.test; public class Constent2 { public void run(String classname) throws ClassNotFoundException, IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { Class<?> classtype = Class.forName(classname); Method[] m = classtype.getDeclaredMethods(); for(int i = 0; i < m.length; i++) { if((m[i].getAnnotation(test.class))instanceof test && m[i].isVarArgs()) { m[i].invoke(classtype.getConstructor(new Class[]{}).newInstance(new Object[]{}),new Object[]{}); } } } public static void main(String[] args) { Constent2 c = new Constent2(); try { c.run("Com.wang.Annotation.DoSometing"); } catch (Exception e) { System.out.println(e); } } } 这个是主要的方法类。 帮我看看是哪儿的问题。。。
1 下一页