[英]Why is there a call to “String.valueOf(Object)” in my string concatenation bytecode?
[英]Why does the println (Object x) method in PrintStream.java call String.valueOf() from outside the synchronized block?
為什么PrintStream.java中的println(Object x)方法從同步塊外部調用String.valueOf()?
為什么不使用現有的打印(對象obj)?
為了表現?
String.valueOf(x)
調用toString()
上方法x
。 此方法的實現可以執行任何操作,包括在此或其他PrintStream
實例上進行同步。 為了避免死鎖,需要在鎖之外調用String.valueOf()
。
由於需要在對象之后立即打印換行符,因此即使有其他線程將其他數據寫入同一PrintStream
也無法重用print
方法。 為此,可在synchronized
塊內調用print
和newLine
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.