Use get<fieldname> default getter approach if is<fieldname> method is not found
@@ -169,15 +169,7 @@ public class Parameterized {
try {
if (method != null) {
if (getter == null) {
- String methodName;
- if(Boolean.class.getSimpleName().toLowerCase().equals(getType().getName())){
- methodName = "is" + method.getName().substring(3);
- } else {
- methodName = "g" + method.getName().substring(1);
- }
-
- getter = object.getClass()
- .getMethod(methodName);
+ setGetter(object);
}
return getter.invoke(object);
} else {
@@ -203,6 +195,22 @@ public class Parameterized {
}
}
+ private void setGetter(Object object) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+ if(Boolean.class.getSimpleName().toLowerCase().equals(getType().getName())){
+ // try is<fieldname> notation
+ try {
+ getter = object.getClass()
+ .getMethod("is" + method.getName().substring(3));
+ // we have found a is<fieldname> getter we can return
+ return;
+ } catch (NoSuchMethodException n){
+ // if not found ignore exception and try with default get<fieldname> below
+ }
+ }
+ getter = object.getClass()
+ .getMethod("g" + method.getName().substring(1));
+ }
+
@Override
public int hashCode() {
final int prime = 31;
