@Test public void testGetGetMethod() throws Exception { ReflectionBean bean = new ReflectionBean(); final long start = System.currentTimeMillis(); final Method uncachedGetter = cache.getGetMethod(bean, "name"); final long uncachedTime = System.currentTimeMillis() - start; final long start2 = System.currentTimeMillis(); final Method cachedGetter = cache.getGetMethod(bean, "name"); final long cachedTime = System.currentTimeMillis() - start2; System.out.println(String.format("getGetMethod uncachedTime: %d, cachedTime: %d", uncachedTime, cachedTime)); assertTrue(cachedTime <= uncachedTime); assertEquals(uncachedGetter, cachedGetter); final String name1 = "uncached"; bean.setName(name1); assertEquals(name1, uncachedGetter.invoke(bean)); final String name2 = "cached"; bean.setName(name2); assertEquals(name2, cachedGetter.invoke(bean)); }
public Method getGetMethod(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } Method method = getCache.get(object.getClass().getName(), fieldName); if( method == null ) { method = ReflectionUtils.findGetter(object, fieldName); getCache.set(object.getClass().getName(), fieldName, method); } return method; }
MethodCache { public Method getGetMethod(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } Method method = getCache.get(object.getClass().getName(), fieldName); if( method == null ) { method = ReflectionUtils.findGetter(object, fieldName); getCache.set(object.getClass().getName(), fieldName, method); } return method; } }
MethodCache { public Method getGetMethod(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } Method method = getCache.get(object.getClass().getName(), fieldName); if( method == null ) { method = ReflectionUtils.findGetter(object, fieldName); getCache.set(object.getClass().getName(), fieldName, method); } return method; }  }
MethodCache { public Method getGetMethod(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } Method method = getCache.get(object.getClass().getName(), fieldName); if( method == null ) { method = ReflectionUtils.findGetter(object, fieldName); getCache.set(object.getClass().getName(), fieldName, method); } return method; }  Method getGetMethod(final Object object, final String fieldName); Method getSetMethod(final Object object, final String fieldName, final Class<?> argumentType); }
MethodCache { public Method getGetMethod(final Object object, final String fieldName) { if( object == null ) { throw new NullPointerException("object should not be null"); } else if( fieldName == null ) { throw new NullPointerException("fieldName should not be null"); } Method method = getCache.get(object.getClass().getName(), fieldName); if( method == null ) { method = ReflectionUtils.findGetter(object, fieldName); getCache.set(object.getClass().getName(), fieldName, method); } return method; }  Method getGetMethod(final Object object, final String fieldName); Method getSetMethod(final Object object, final String fieldName, final Class<?> argumentType);  }