Guest User

Untitled

a guest
Aug 10th, 2018
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IllegalArgumentException: wrong number of arguments
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.lang.reflect.Method;
  4.  
  5. public class Reflection {
  6.  
  7. /**
  8. * @param args
  9. * @throws InvocationTargetException
  10. * @throws IllegalArgumentException
  11. * @throws IllegalAccessException
  12. */
  13. public static void main(String[] args) throws IllegalAccessException,
  14. InvocationTargetException, IllegalArgumentException {
  15. Class<Cls> cls = Cls.class;
  16. Method[] methods = cls.getMethods();
  17. for (Method m : methods) {
  18. m.invoke(cls);
  19. }
  20. }
  21.  
  22. }
  23.  
  24. class Cls {
  25. public static void method1() {
  26. System.out.println("Method1");
  27. }
  28.  
  29. public static void method2() {
  30. System.out.println("Method2");
  31. }
  32. }
  33.  
  34. m.invoke(cls, null);
RAW Paste Data