java - 关于重写toString()方法
PHP中文网
PHP中文网 2017-04-18 09:33:51
0
3
860

想请教各路大神~~
如[id=" + id + "]是什么意思呢?/(ㄒoㄒ)/~~
求解答~/(ㄒoㄒ)/~~

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
黄舟

toString, as the name suggests, represents this variable in the form of a string. It can also be understood that this variable/class/instance is expressed as XXXX in a string. As for whether this string is unique, that is another matter.

Obviously, the toString method here just uses string concatenation to express its attributes, for example:

println(this.toString())

The output is similar to: Goddess [id=1 , user_name ="aaaa", sex="man".........]

The value obtained by toString is generally not for machines to see, but for people to see. In other words, in the toString method, we must find ways to let people see clearly at a glance what variable it is and what its value is, or the function of this class can be seen at a glance.

[id=" + id + "] is very simple. The output result is a string similar to [id=" + id + "]很简单,输出结果就是类似Goddess [id=1 , user_name ="aaaa", sex="man".........], which expresses that the name of this class (this variable) is Goddess, and it has XX attributes. The value of the attribute id is 1, the value of sex is man.

黄舟

This is using the plus sign to concatenate strings. [id=" + id + "]It indicates the value of the id. The advantage of this is that it will look more friendly when printed to the console.

Peter_Zhu

Is it because I don’t understand string concatenation and regard it as the assignment operation of id?

[id=" + id + "

The first quote above is the quote at the end of the previous string, and the second is the quote at the beginning of the next string:

"...[id=" //第一个字符串
+ id + //拼接的id值,自动将数值等类型转换为字符串
"..." //第二个字符串
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!