- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- public class Test14 {
- public static void main(String[] args) {
- int[] a = {1,2,4};
- Test t = new Test();
- try {
- Method m = Test.class.getMethod("sopArr", int[].class);
- //Method m = Test.class.getMethod("sopArr", a.class);
-
- m.invoke(t, a);
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- class Test {
- public static void main(String[] args) {
-
- }
-
- public static void sopArr(int[] a){
- for(int i:a){
- System.out.println(i);
- }
- }
- }
复制代码 |