Advertisement
Guest User

Untitled

a guest
May 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.lang.reflect.*;
  2.  
  3. public class ClassDemo {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. ClassDemo cls = new ClassDemo();
  8. Class c = cls.getClass();
  9.  
  10. try {
  11. // parameter type is null
  12. Method m = c.getMethod("show", null);
  13. System.out.println("method = " + m.toString());
  14. }
  15.  
  16. catch(NoSuchMethodException e) {
  17. System.out.println(e.toString());
  18. }
  19.  
  20. try {
  21. // method Long
  22. Class[] cArg = new Class[1];
  23. cArg[0] = Long.class;
  24. Method lMethod = c.getMethod("showLong", cArg);
  25. System.out.println("method = " + lMethod.toString());
  26. }
  27. catch(NoSuchMethodException e) {
  28. System.out.println(e.toString());
  29. }
  30. }
  31.  
  32. public Integer show() {
  33. return 1;
  34. }
  35.  
  36. public void showLong(Long l) {
  37. this.l = l;
  38. }
  39. long l = 78655;
  40. }
  41.  
  42. method = public java.lang.Integer ClassDemo.show()
  43. method = public void ClassDemo.showLong(java.lang.Long)
  44.  
  45. method = show()
  46. method = showLong(Long)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement