JDK-8273220 : AutoCloseable And Try-With-Resources Without Variable Declaration
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 16
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2021-08-31
  • Updated: 2021-09-01
  • Resolved: 2021-09-01
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Suggesting to modify javac to allow try-with-resources without a variable declaration, causing an implicit variable declaration to be inserted by the complier.  This can be helpful in reducing code when dealing with resources that are opened and closed, but where the resource itself need not be exposed.
Example:
try (new SomethingToClose()) {
  ... do something while something to close is open
}



Comments
The suggestion was evaluated during Project Coin/JSR 334 and was found to be problematic, see JDK-7011742. Closing as will not fix.
01-09-2021

RFE to allow try-with-resources without any variable declaration for the resource. It can be helpful in the situation where the resource itself need not be exposed.
01-09-2021