Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.*;
- public class ClassDemo {
- public static void main(String[] args) {
- ClassDemo cls = new ClassDemo();
- Class c = cls.getClass();
- try {
- // parameter type is null
- Method m = c.getMethod("show", null);
- System.out.println("method = " + m.toString());
- }
- catch(NoSuchMethodException e) {
- System.out.println(e.toString());
- }
- try {
- // method Long
- Class[] cArg = new Class[1];
- cArg[0] = Long.class;
- Method lMethod = c.getMethod("showLong", cArg);
- System.out.println("method = " + lMethod.toString());
- }
- catch(NoSuchMethodException e) {
- System.out.println(e.toString());
- }
- }
- public Integer show() {
- return 1;
- }
- public void showLong(Long l) {
- this.l = l;
- }
- long l = 78655;
- }
- method = public java.lang.Integer ClassDemo.show()
- method = public void ClassDemo.showLong(java.lang.Long)
- method = show()
- method = showLong(Long)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement