Java 在执行加法时如何处理长变量?
错误的版本1:
Vector speeds = ... //whatever, speeds.size() returns 2
long estimated = 1l;
long time = speeds.size() + estimated; // time = 21; string concatenation??
错误的版本 2:
Vector speeds = ... //whatever, speeds.size() returns 2
long estimated = 1l;
long time = estimated + speeds.size(); // time = 12; string concatenation??
正确版本:
Vector speeds = ... //whatever, speeds.size() returns 2
long estimated = 1l;
long size = speeds.size();
long time = size + estimated; // time = 3; correct
我不明白,为什么 Java 将它们连接起来。
任何人都可以帮助我,为什么连接两个原始变量?
问候,格尔达