I am asking this purely to determine the worthwhile-ness of implementing the class in Question …
Do you know of a Java utility class that takes an un-synchronized instance, uses reflection to investigate that instance, and returns the input instance ‘wrapped’ within synchronized calls ?
( ie: A factory which creates a synchronized delegate class for any instance )
I like Jon Skeet’s answer; it’s seeing the forest instead of the trees. But to answer the question:
Assuming that the instance belongs to some interface, it’s easy to use
java.lang.reflect.Proxyto do this.This code is not tested, by the way. Use at your own risk.