[英]JAVA : regarding System.out
JAVA : is there a difference between the two references "p" && "pp"? JAVA:两个引用“ p”和&“ pp”之间有区别吗?
PrintStream p = new PrintStream(System.out);
p.println("lol");
PrintStream pp = System.out;
pp.println("lol");
I would just like to shorten the System.out.println(); 我只想缩短System.out.println(); statement for some prototyping.
声明一些原型。 cheers!
干杯! matt
亚光
没有功能上的差异,尽管第一个创建了不需要的新对象,因此效率稍低。
No, there's no behavioral difference between the two. 不,两者之间在行为上没有区别。
System.out
is already a PrintStream
, and a new PrintStream(otherPrintStream)
just creates a wrapper object which only delegates to the given PrintStream
. System.out
已经是一个PrintStream
,并且new PrintStream(otherPrintStream)
仅创建一个包装对象,该包装对象仅委托给给定的PrintStream
。
As @MarkoTopolnik suggest, you can even do 正如@MarkoTopolnik所建议的,您甚至可以
import static java.lang.System.out;
and just do 然后做
out.println("lol");
if you want to keep it short. 如果您想使其简短。
No difference. 没有不同。
Both the statement will effect the same. 这两个语句将具有相同的效果。 Slightly difference is we are creating a new object of PrintStream class in first statement unnecessary.
稍有不同的是,我们不需要在第一条语句中创建PrintStream类的新对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.