为什么在情况 2:Java 7 中,相同的值会出现两个不同的答案?
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
System.out.println("Case 1:");
long size=(long)1<<39;
System.out.println("size :"+size);
size=1024*1024*1024*512l;
System.out.println("size :"+size);
System.out.println("Case 2:");
size=(long)1<<41;
System.out.println("size :"+size);
size=1024*1024*1024*1024*2l;
System.out.println("size :"+size);
}
}
Run Code Online (Sandbox Code Playgroud)
下面从 Ideone 给出了答案。
Case 1:
size :549755813888
size :549755813888
Case 2:
size :2199023255552
size :0
Run Code Online (Sandbox Code Playgroud)