阅读下面的代码
import java.util.*; import java.math.*; public class Third{ public static void main(String[] args){ final long VALUE = 24 * 60 * 60 * 1000 * 1000; System.out.println(VALUE); } }
这是计算一天的微秒数,是否正确?
输出:500654080
这是不是一天的毫秒数呢?
继续看下面的代码:
import java.util.*;public class Third{ public static void main(String[] args){ final long VALUE = 24L * 60 * 60 * 1000 * 1000; System.out.println(VALUE); } }
输出:86400000000
原来第一段代码已经被截了,因为24,60,1000都是int型,因此表达式会是int,之后再向上转型为long。
原文:http://www.cnblogs.com/qionghua520/p/4370630.html