Page 1 of 1

Re: About Question enthuware.ocpjp.v11.2.1245 :

Posted: Tue Mar 14, 2023 2:26 pm
by edufin166@yahoo.com
This alternative is a bit confusing...
"Resources are closed in the reverse order of their declaration in the try clause (or creation, if they are created in the try clause)."

It means: If I create my resources "outside" try-clause, ... are they will be closed in sequential order? Of course, not.

EX: Resources were created "outside" try-clause
ZipFile resource1 = new ZipFile(zipFileName);    
BufferedWriter resource2 = Files.newBufferedWriter(path, charset);  
try (         resource1;           
resource2;         
) {         ...     }

Am I wronged?

Re: About Question enthuware.ocpjp.v11.2.1245 :

Posted: Tue Mar 14, 2023 10:16 pm
by admin
Please read the statement carefully:
Resources are closed in the reverse order of their declaration in the try clause. That is what is happening in your example, right?

The part in parentheses is about the case when resources are created (instead of just declared) in try clause.