Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Locale; import android.util.Log; public class Main { private static Method getColumnGetMethod(Class<?> entityType, Field field, String suffix) { String fieldName = field.getName(); Method getMethod = null; if (field.getType() == boolean.class) { getMethod = getBooleanColumnGetMethod(entityType, fieldName, suffix); } if (getMethod == null) { String methodName = "get" + fieldName.substring(0, 1).toUpperCase(Locale.getDefault()) + fieldName.substring(1) + suffix; try { getMethod = entityType.getDeclaredMethod(methodName); } catch (NoSuchMethodException e) { Log.d("T", methodName + " not exist"); } } return getMethod; } private static Method getBooleanColumnGetMethod(Class<?> entityType, final String fieldName, String suffix) { String methodName = "is" + fieldName.substring(0, 1).toUpperCase(Locale.getDefault()) + fieldName.substring(1) + suffix; if (isStartWithIs(fieldName)) { methodName = fieldName + suffix; } try { return entityType.getDeclaredMethod(methodName); } catch (NoSuchMethodException e) { Log.d("L", methodName + " not exist"); } return null; } private static boolean isStartWithIs(final String fieldName) { return fieldName != null && fieldName.startsWith("is"); } }