[英]Difference between System.out and Printstream
Is there any difference in these statements 这些陈述有什么不同吗?
System.out.println(error);
AND 和
PrintStream ps = new PrintStream((OutputStream)System.out);
ps.println(error);
System.out
is already a PrintStream
, System.out
已经是一个PrintStream
,
PrintStream ps = new PrintStream((OutputStream)(System.out));
would only wrap it once more which seems pointless. 只会再次包裹它,这似乎毫无意义。
Basically, there is no difference. 基本上没有区别。 The second way is too prolonged.
第二种方式太长了。 out is a static field of type java.io.PrintStream in System class.
out是System类中java.io.PrintStream类型的静态字段。 You could directly use it instead of casting it to Outputstream and again wrapping it inside another PrintStream reference.
您可以直接使用它而不是将其转换为Outputstream并再次将其包装在另一个PrintStream引用中。 They both are going to use the same underlying PrintStream object regardless.
无论如何,它们都将使用相同的底层PrintStream对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.