Can i change java.util.concurrent.locks.Lock into java.util.concurrent.locks.ReentrantReadWriteLock;

150 Views Asked by At

I have a method which creates the lock.

ReadWriteLock  lock = new ReentrantReadWriteLock();

Then I pass this object into a method using Lock Interface.

method(Lock lock)

inside the method I just do the following.

final ReentrantReadWriteLock currentLock = (ReentrantReadWriteLock) lock;
1

There are 1 best solutions below

0
On BEST ANSWER

A ReentrantReadWriteLock is not a Lock. It contains two related Locks a read lock and a write lock. You can pass either of these but you can't get the original ReentrantReadWriteLock back.