AutoCloseable
实例,也称为 Automatic Resource Management。
这意味着还报告在 try-with-resources 可用前所使用的“在 try
前面/中打开,在 finally
中关闭”的样式。
在 Java 7 及更高版本中开发时,该检查意在取代所有已打开但未安全关闭的检查。
示例:
private static void foo() throws IOException {
InputStream profile = Thread.currentThread().getContextClassLoader().getResourceAsStream("/someFile");
System.out.println(profile.read());
}
使用以下选项配置检查:
AutoCloseable
的子类。
java.util.stream.Stream
,该检查仍将报告从 java.nio.file.Files
方法 lines()
、walk()
、list()
以及 find()
返回的流。
这些流包含需要关闭的关联 I/O 资源。
AutoCloseable
。
AutoCloseable
。
启用此选项时,工厂方法的结果也将被忽略。
AutoCloseable
实例作为方法调用参数传递时,该检查是否应进行报告。
如果启用此选项,该检查将假定所调用方法中的资源已关闭。
不会忽略名称中含有 'close' 和 AutoCloseable
参数的 finally
块中的方法调用。