protected Method findGetter ( Object data , String property ) throws IntrospectionException { Class < ? > clazz = getClass ( data ) ; String key = clazz . getName ( ) + ":" + property ; Method method = methods . get ( key ) ; if ( method == null ) { Method newMethod = null ; PropertyDescriptor [ ] props = Introspector . getBeanInfo ( clazz ) . getPropertyDescriptors ( ) ; for ( PropertyDescriptor prop : props ) { if ( prop . getName ( ) . equalsIgnoreCase ( property ) ) { newMethod = prop . getReadMethod ( ) ; } } method = methods . putIfAbsent ( key , newMethod ) ; if ( method == null ) { // put succeeded, use new value method = newMethod ; } } return method ; }
Cache the method if possible using the classname and property name to allow for similar named methods .