为什么 DataOutputStream 不创建“资源泄漏:流从未关闭”警告。
public static void main(String[] args) {
try{
DataOutputStream o = new DataOutputStream(System.out);
o.writeInt(12);
}
catch(IOException ex){
}
}
我以为是因为它扩展了FilterOutputStream 但是在扩展我自己的类时,它给出了警告。
最佳答案
我认为编译器(至少是我的 Eclipse 编译器)知道 System.out
永远不应该关闭。尝试 DataOutputStream o = new DataOutputStream(new FileOutputStream("test"));
,您会看到警告。
关于java - 为什么 DataOutputStream 不创建 "Resource leak: stream never closed "警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24593052/