如果 2 个int
值的乘积不适合 a int
,因此我将其存储在 along
中,是否需要long
在每个操作数之前(或至少在其中一个操作数之前)指定显式转换为?或者即使没有强制转换,编译器是否正确处理它?
这将是显式代码:
public final int baseDistance = (GameCenter.BLOCKSIZE * 3/2);
long baseDistanceSquare = (long)baseDistance * (long)baseDistance;
或者下面的代码就足够了吗?
long baseDistanceSquare = baseDistance * baseDistance;