With reference to my question Any risk in a AutoCloseable wrapper for java.util.concurrent.locks.Lock?, I am wondering why the try-with-resource-statement require a named local variable at all.
My current usage is as follows:
try (AutoCloseableReentrantReadWiteLock.Lock l = _lock.writeLock()) {
// do something
}
The variable l
is unused inside the try block and only pollutes the namespace. From what I can remember the analogous C# using
-statement does not require a local named variable.
Is there any reason the following could not have been supported, with an anonymous local variable that is closed at the end of try block?
try (_lock.writeLock()) {
// do something
}