tostring() is implicitly called… how?

前端 未结 3 1967
囚心锁ツ
囚心锁ツ 2021-01-17 04:59

In the following code, how is toString() is implicitly called?

class Payload {
    private int weight;
    public Payload (int w) {
        weig         


        
3条回答
  •  野的像风
    2021-01-17 05:38

    This is just a language feature which is available for free. See Concatenating strings section:

    Such a concatenation can be a mixture of any objects. For each object that is not a String, its toString() method is called to convert it to a String.

提交回复
热议问题