@Test public void shouldReturnNullMethodWhenMethodNotFound() { assertThat(Reflection.getMethod(String.class, "thereWillNeverBeMethodWithThisName")) .isNull(); }
public static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName) { if (clazz == null) { return null; } try { return clazz.getMethod(methodName); } catch (Exception e) { logger.debug(e.getMessage(), e); return null; } }
Reflection { public static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName) { if (clazz == null) { return null; } try { return clazz.getMethod(methodName); } catch (Exception e) { logger.debug(e.getMessage(), e); return null; } } }
Reflection { public static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName) { if (clazz == null) { return null; } try { return clazz.getMethod(methodName); } catch (Exception e) { logger.debug(e.getMessage(), e); return null; } } private  Reflection(); }
Reflection { public static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName) { if (clazz == null) { return null; } try { return clazz.getMethod(methodName); } catch (Exception e) { logger.debug(e.getMessage(), e); return null; } } private  Reflection(); static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName); static @Nullable Field getDeclaredField(@Nullable Class<?> clazz, String fieldName); @SuppressWarnings("unchecked") static T invoke(@Nullable Method method, Object obj); @SuppressWarnings("unchecked") static T invokeWithDefault(@Nullable Method method, Object obj, T defaultValue); static @Nullable Object getFieldValue(@Nullable Field field, Object obj); }
Reflection { public static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName) { if (clazz == null) { return null; } try { return clazz.getMethod(methodName); } catch (Exception e) { logger.debug(e.getMessage(), e); return null; } } private  Reflection(); static @Nullable Method getMethod(@Nullable Class<?> clazz, String methodName); static @Nullable Field getDeclaredField(@Nullable Class<?> clazz, String fieldName); @SuppressWarnings("unchecked") static T invoke(@Nullable Method method, Object obj); @SuppressWarnings("unchecked") static T invokeWithDefault(@Nullable Method method, Object obj, T defaultValue); static @Nullable Object getFieldValue(@Nullable Field field, Object obj);  }