1 public class Foo {
2 public static void main(String[]a){
3 foo(1000000000); // output: 1000000000
4 foo(1000000000 * 10); // output: 1410065408
5 foo((long)1000000000 * 10); // output: 10000000000
6
7 long l = 1000000000 * 10;
8 foo(l); // output: 1410065408
9 //long m = 10000000000; // compile error
10 }
static void foo(long l){
System.out.println(l);
}
}
为什么第 4 行输出:1410065408 而不是 10000000000?
为什么第 9 行是编译错误?编译器不能创建 aLong
因为预期的类型是 aLong
吗?