@Test public void testMethodByName() throws Exception { Method source = Utils.methodByName(String.class, "equals"); assertNotNull(source); assertEquals("equals", source.getName()); assertNull(Utils.methodByName(String.class, "not_equals")); }
public static <T> Method methodByName(Class<T> aClass, String name) { for (Method m : aClass.getMethods()) { if (m.getName().equals(name)) { return m; } } return null; }
Utils { public static <T> Method methodByName(Class<T> aClass, String name) { for (Method m : aClass.getMethods()) { if (m.getName().equals(name)) { return m; } } return null; } }
Utils { public static <T> Method methodByName(Class<T> aClass, String name) { for (Method m : aClass.getMethods()) { if (m.getName().equals(name)) { return m; } } return null; } private  Utils(); }
Utils { public static <T> Method methodByName(Class<T> aClass, String name) { for (Method m : aClass.getMethods()) { if (m.getName().equals(name)) { return m; } } return null; } private  Utils(); static Method methodByName(Class<T> aClass, String name); static Object executeOnInstance(Object object, Method method, Object[] args); static T newInstance(Class<T> aClass); }
Utils { public static <T> Method methodByName(Class<T> aClass, String name) { for (Method m : aClass.getMethods()) { if (m.getName().equals(name)) { return m; } } return null; } private  Utils(); static Method methodByName(Class<T> aClass, String name); static Object executeOnInstance(Object object, Method method, Object[] args); static T newInstance(Class<T> aClass);  }