/** * Whether the specified JavaBeans property exists on the given type or not. * * @param clazz the type of interest * @param property the JavaBeans property name * @param elementType the element type to check, must be either {@link ElementType#FIELD} or * {@link ElementType#METHOD}. * @return {@code true} if the specified property exists, {@code false} otherwise */ public static boolean propertyExists(Class<?> clazz, String property, ElementType elementType) { if ( ElementType.FIELD.equals( elementType ) ) { return getDeclaredField( clazz, property ) != null; } else { String capitalizedPropertyName = capitalize( property ); Method method = getMethod( clazz, PROPERTY_ACCESSOR_PREFIX_GET + capitalizedPropertyName ); if ( method != null && method.getReturnType() != void.class ) { return true; } method = getMethod( clazz, PROPERTY_ACCESSOR_PREFIX_IS + capitalizedPropertyName ); if ( method != null && method.getReturnType() == boolean.class ) { return true; } } return false; }