I was asked in a interview following
There is a class Customer which is not synchronized. How do you access it in a synchronized manner. The constraint is that you do do not have access to
java code of Customer class.
I answered: I will create a wrapper class using decorator
pattern and expose synchronized version of all the methods of Customer class.
e.g
I told that I will ask the developer to use this class in a polymorpic manner instead of Customer class.
The interviewer said I can simply achieve it by putting it in a synchronized collection.
I think the solution of using synchronized collection will not work because the collection is only
thread safe and not the object that collection contains(ie Customer object)
My question:
is my reasoning correct? If not can anybody help me understand how interviewer's solution will work.