Java tutorial
//package com.java2s; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Locale; import android.content.Context; public class Main { /** * @param context * @param type * @param field * @param errResId * @param methodPrefix * @param methodParameters */ public static void checkIfMethodExists(Context context, Class<?> type, Field field, int errResId, String methodPrefix, Class<?>... methodParameters) { try { Method m = type.getDeclaredMethod(methodPrefix + getFirstLetterUppercased(field.getName()), methodParameters); if (!Modifier.isPublic(m.getModifiers()) || Modifier.isStatic(m.getModifiers())) throw new RuntimeException(context.getString(errResId, field.getName())); } catch (NoSuchMethodException e) { throw new RuntimeException(context.getString(errResId, field.getName())); } } /** * @param s * @return */ public static String getFirstLetterUppercased(String s) { StringBuilder sb = new StringBuilder(s.substring(0, 1).toUpperCase(Locale.getDefault())); sb.append(s.substring(1)); return sb.toString(); } }