toString() 解释中的“....当倒数第二条语句中需要一串字符时”

"....when a string of character is needed in the next to last statement" in toString() explanation

关于此节选中的 toString() 方法,作者试图告诉我们什么:

The toString() method of the Integer class is automatically used when a string of characters is needed in the next to last statement. The toString() method of the Double class is automatically used when a string of characters is needed last statement.

讨论这段代码时:

Integer value = new Integer(103);
Double dvalue = new Double(-32.78);

System.out.println( "Integer object holds: " + value );
System.out.println( "Double  object holds: " + dvalue );

The toString() method of the Integer class is automatically used when a string of characters is needed in the next to last statement.

您引用的文字附有代码。代码中倒数第二个语句是:

System.out.println( "Integer object holds: " + value );

其中 valueInteger 的实例。

要执行串联 "Integer object holds: " + value,必须将 value 转换为字符串。调用 IntegertoString() 方法来执行此转换。

同样的说法:

System.out.println( "Double  object holds: " + dvalue ); 

涉及调用DoubletoString()方法将dvalue转换为字符串。

@khelwood 给出了很好的解释。作者想告诉你的是

System.out.println( "Integer object holds: " + value );   and 

System.out.println( "Integer object holds: " + Integer.toString(value));

相同。