Difference between System.out and Printstream

前端 未结 3 1131
傲寒
傲寒 2020-12-10 17:28

Is there any difference in these statements

System.out.println(error);

AND

PrintStream ps = new PrintStream((OutputStream)S         


        
3条回答
  •  孤城傲影
    2020-12-10 17:59

    Basically, there is no difference. The second way is too prolonged. out is a static field of type java.io.PrintStream in System class. You could directly use it instead of casting it to Outputstream and again wrapping it inside another PrintStream reference. They both are going to use the same underlying PrintStream object regardless.

提交回复
热议问题