public static Method getGetter(Class clazz, String property) { String isGet = ReflectionUtil.getIsGetter(property); property = ReflectionUtil.getGetter(property); for (Method meth : clazz.getMethods()) { if ((meth.getModifiers() & PUBLIC) != 0 && meth.getParameterTypes().length == 0 && (property.equals(meth.getName()) || isGet.equals(meth.getName()))) { return meth; } } return null; }
public static Method getGetter(Class clazz, String property) { String simple = "get" + property; String simpleIsGet = "is" + property; String isGet = ReflectionUtil.getIsGetter(property); String getter = ReflectionUtil.getGetter(property); Method candidate = null; for (Method meth : clazz.getMethods()) { if ((meth.getModifiers() & PUBLIC) != 0 && (meth.getModifiers() & STATIC) == 0 && meth.getParameterTypes().length == 0 && (getter.equals(meth.getName()) || property.equals(meth.getName()) || ((isGet.equals(meth.getName()) || simpleIsGet.equals(meth.getName())) && meth.getReturnType() == boolean.class) || simple.equals(meth.getName()))) { if (candidate == null || candidate.getReturnType().isAssignableFrom(meth.getReturnType())) { candidate = meth; } } } return candidate; }
public static Method getGetter(Class clazz, String property) { String simple = "get" + property; String simpleIsGet = "is" + property; String isGet = ReflectionUtil.getIsGetter(property); String getter = ReflectionUtil.getGetter(property); Method candidate = null; if (Collection.class.isAssignableFrom(clazz) && "isEmpty".equals(isGet)) { try { return Collection.class.getMethod("isEmpty"); } catch (NoSuchMethodException ignore) {} } for (Method meth : clazz.getMethods()) { if ((meth.getModifiers() & PUBLIC) != 0 && (meth.getModifiers() & STATIC) == 0 && meth.getParameterTypes().length == 0 && (getter.equals(meth.getName()) || property.equals(meth.getName()) || ((isGet.equals(meth.getName()) || simpleIsGet.equals(meth.getName())) && meth.getReturnType() == boolean.class) || simple.equals(meth.getName()))) { if (candidate == null || candidate.getReturnType().isAssignableFrom(meth.getReturnType())) { candidate = meth; } } } return candidate; }