• Post Reply Bookmark Topic Watch Topic
  • New Topic

Try-with-resources best practices  RSS feed

 
salvin francis
Bartender
Posts: 1479
21
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following is a good practice to follow ?



or



or do they both mean the same ?

 
Stephan van Hulst
Saloon Keeper
Posts: 6985
110
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends.

I usually just use the second variant, but there may be a case where you want to use several different wrappers around an inner stream.

For instance, let's say you want to read both Java primitives from a stream, and characters in a certain encoding. You can wrap the inner stream twice to suit your needs:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!