List of usage examples for org.springframework.util TypeUtils isAssignable
private static boolean isAssignable(WildcardType lhsType, Type rhsType)
From source file:org.carewebframework.shell.property.PropertyUtil.java
/** * Returns the requested method from an object instance. * /*ww w . ja va 2s . c o m*/ * @param methodName Name of the setter method. * @param instance Object instance to search. * @param valueClass The desired property return type (null if don't care). * @param setter If true, search for setter method signature. If false, getter method signature. * @return The requested method. * @throws NoSuchMethodException If method was not found. */ private static Method findMethod(String methodName, Object instance, Class<?> valueClass, boolean setter) throws NoSuchMethodException { if (methodName == null) { return null; } int paramCount = setter ? 1 : 0; for (Method method : instance.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == paramCount) { Class<?> targetClass = setter ? method.getParameterTypes()[0] : method.getReturnType(); if (valueClass == null || TypeUtils.isAssignable(targetClass, valueClass)) { return method; } } } throw new NoSuchMethodException("Compatible method not found: " + methodName); }