Online Java Compiler By
JavaTpoint.com
import java.lang.reflect.*; public class ClassgetMethodExample1 { public static void main(String[] args) { ClassgetMethodExample1 class1 = new ClassgetMethodExample1(); Class cls = class1.getClass(); try { Method mthd = cls.getMethod("showMethod", null); System.out.println("method = " + mthd.toString()); } catch(NoSuchMethodException e) { System.out.println(e.toString()); //print exception object } try { Class[] aarg = new Class[1]; aarg[0] = Long.class; Method lmthd = cls.getMethod("showLongMethod", aarg); System.out.println("method = " + lmthd.toString()); } catch(NoSuchMethodException e) { System.out.println(e.toString()); //print exception object } } public Integer showMethod() { return 1; } public void showLongMethod(Long lng) { this.lng = lng; } long lng = 788995; }
Output