Try-with-resource

On the other hand, the var type is a very nice fit for try-with-resource, as in the following example:

// explicit type
try (PrintWriter writer = new PrintWriter(new File("welcome.txt"))) {
writer.println("Welcome message");
}
// using var
try (var writer = new PrintWriter(new File("welcome.txt"))) {
writer.println("Welcome message");
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset