我有以下代码和输出:
public static void main(String[] args) {
long lon = 1000;
lon = lon * 3600;
lon = lon * 24;
lon = lon * 365;
System.out.println("lon: " + lon);
long lon2 = 1000 * 3600 * 24 * 365;
System.out.println("lon2: " + lon2);
}
lon: 31536000000
lon2: 1471228928
我想某种溢出正在发生lon2
,但我似乎无法弄清楚。结果远低于 Long.MAX_VALUE。任何想法?