Le 01/03/2011 10:46, Alan Bateman a écrit :
Stuart Marks wrote:
Here's a small webrev with changes to a handful of java.io tests to use TWR.

http://cr.openjdk.java.net/~smarks/reviews/7022624/webrev.0/



* test/java/io/OutputStreamWriter/Encode.java

Pretty clearly a ServerSocket is a distinct resource from a Socket returned from the accept() call. However, does Socket.getInputStream() represent a distinct resource from the Socket? In this case it seemed most sensible to unroll them into separate resource variables, but again I could go either way on this.
I wouldn't bother but would instead reduce this down to three resources, maybe:

try (ServerSocket listener = ss;
     Socket s = listener.accept();
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()))
{
   ...
}

While you are there, I assume ss should be final.

Local variables declared in a try-with resources are implicitly final.


-Alan.


Rémi


Reply via email to