Online Java Compiler By
JavaTpoint.com
import java.lang.reflect.Method; public class ReflectMethodequalsExample2 { public static void main(String[] args) throws NoSuchMethodException, SecurityException, ClassNotFoundException { Method[] mthd = DemoClassNo1.class.getMethods(); Method mthd2 = DemoClassNo1.class.getMethod("adddata", String.class); System.out.println("First Method object from array :::::" +mthd[0]); System.out.println("Method object created by :::::" + mthd2); if (mthd[0].equals(mthd2)) { System.out.println("Both Method objects are equal"); } else { System.out.println("Both Method objects are not equal"); } } } class DemoClassNo1 { private String data1; public DemoClassNo1 () { } public String adddata(String data2) { return this.data1 + data2; } }
Output