Here you can find the source of getGetter(Class> clazz, Field field)
public static Method getGetter(Class<?> clazz, Field field) throws SecurityException, NoSuchMethodException
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Locale; public class Main { public static Method getGetter(Object object, Field field) throws SecurityException, NoSuchMethodException { return getGetter(object.getClass(), field); }//from w w w . j ava 2 s.c o m public static Method getGetter(Class<?> clazz, Field field) throws SecurityException, NoSuchMethodException { Method getter = clazz.getMethod(getGetterName(field)); if (!getter.getReturnType().equals(field.getType())) { throw new NoSuchMethodException(); } return getter; } public static String getGetterName(Field field) { String name = field.getName(); if (field.getType().equals(boolean.class)) { return "is" + name.substring(0, 1).toUpperCase(Locale.US) + name.substring(1); } else { return "get" + name.substring(0, 1).toUpperCase(Locale.US) + name.substring(1); } } }