0

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;
Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40
user882196
  • 1,691
  • 9
  • 24
  • 39
  • Just take a look into javadoc of ReadWriterLock / ReentrantReadWriteLock, and see which interface is implemented by it. This is something you can answer yourself, that ReadWriteLock is not a Lock – Adrian Shum Nov 30 '11 at 10:23

1 Answers1

1

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130