Multiplying long values?

前端 未结 5 992
盖世英雄少女心
盖世英雄少女心 2020-12-03 14:08
class Main {  
   public static void main (String[] args){  
     long value = 1024 * 1024 * 1024 * 80;  
     System.out.println(Long.MAX_VALUE);  
     System.out.         


        
5条回答
  •  孤城傲影
    2020-12-03 14:48

    I suspect it's because by default java treats literals as integers, not longs. So, without the L on 80 the multiplication overflows.

提交回复
热议问题