In java 7 or 8 if a resource is already declared outside the try-with-resources statement, we should re-refer it with local variable. That means we have to declare a new variable in try block. Let us look at the code explaining above argument :
In Java 9 we are not required to create this local variable. It means, if we have a resource which is already declared outside a try-with-resources statement as final or effectively final, then we do not have to create a local variable referring to the declared resource, that declared resource can be used without any issue. Let us look at java code explaining above argument.
This article is contributed by Abhishek Verma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Automatic Resource Management in Java | try with resource statements
- Writing clean if else statements
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples