Java long assignment confusing

前端 未结 9 1086
一个人的身影
一个人的身影 2021-01-24 05:17

Why does this java code

long a4 = 1L;
long a3 = 1;
long a2 = 100L * 1024 * 1024 * 1024;
long a1 = 100 * 1024 * 1024 * 1024;
System.out.println(a4);
System.out.pr         


        
9条回答
  •  有刺的猬
    2021-01-24 06:06

    It might be that the expression on the right of a1 is first calculated as an int and later on converted to long. If it equals 0 as an int it'll stay 0 as a long

提交回复
热议问题