java toString()返回此 [英] java toString() returning this
本文介绍了java toString()返回此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在String toString()
方法返回此
,当我传递 System时。 out.println()
它打印 String
的内容。对我来说这是多么令人困惑。请来解释一下。
In String toString()
method returns this
and when i pass it System.out.println()
it prints the content of the String
. It is confusing for me how is that happening. can comeone explain please.
public String toString(){
return this;
}
谢谢。
推荐答案
Java中 Object
上定义的 toString
方法负责将对象转换为String表示形式。由于 String
已经是String, toString
方法只返回自身。
The toString
method, defined on Object
in Java is responsible for converting the object to a String representation. Since String
is already a String, the toString
method simply returns itself.
这篇关于java toString()返回此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文