AutoCloseable
实例,也称 自动资源管理。
这意味着还报告在 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' 的 finally
块和 AutoCloseable
实参中的方法调用。