Make a functional interface
@FunctionalInterface
public RulesFact {
Object getPropertyValue(String propertyName);
}
An instance a lambda inside a method.
public RulesFact rulesFactImpl(Object o) {
return propertyName->PropertyAccessorFactory.forBeanPropertyAccess(o).getPropertyValue(propertyName);
}
Is there a difference between this method and the above one? In the above one, does the PropertyAccessorFactory.forBeanPropertyAccess method get called each time the lambda is executed? Is there a difference in thread safety?
public RulesFact rulesFactImpl(Object o) {
BeanWrapper accessor = PropertyAccessorFactory.forBeanPropertyAccess(o);
return propertyName->accessor.getPropertyValue(propertyName);
}
Javadocs on above reflection utils: Package org.springframework.beans