最佳答案
How does the try-with feature work for AutoCloseable
variables that have been declared null
?
I assumed this would lead to a null pointer exception when it attempts to invoke close
on the variable, but it runs no problem:
try (BufferedReader br = null){
System.out.println("Test");
}
catch (IOException e){
e.printStackTrace();
}