Why DataOutputStream does not generate a warning "Resource leak error: stream never closes"

Why DataOutputStream does not generate the warning "Resource leak error: stream never closes."

public static void main(String[] args) {
    try{
        DataOutputStream o = new DataOutputStream(System.out);
        o.writeInt(12);
    }
    catch(IOException ex){

    }
}

I thought this was because it extends FilterOutputStream. But when expanding my own class, it gives a warning.

+4
source share
3 answers

I think that the compiler (at least my Eclipse compiler) knows that it System.outshould never be closed. Try DataOutputStream o = new DataOutputStream(new FileOutputStream("test"));it and you will see a warning.

+2
source

, DataOutputStream , , , . , , DataOutputStream .

, , , .

+1

DataOutputStream , .

FD . System.out, , .

, IDE.

0

Source: https://habr.com/ru/post/1547295/


All Articles