Firstly, the method below does not compile, because it lacks a return type and should be Long.MAX_VALUE instead of Long.Max_value .
public static boolean isBiggerThanMaxLong(long value) { return value > Long.Max_value; }
The above method will never be able to return true since you are comparing a long value with Long.MAX_VALUE , see the signature of the method that you can only pass long Any long can be as large as Long.MAX_VALUE , it cannot be larger than this,
You can try something like this with the BigInteger class:
public static boolean isBiggerThanMaxLong(BigInteger l){ return l.compareTo(BigInteger.valueOf(Long.MAX_VALUE))==1?true:false; }
The code below will return true :
BigInteger big3 = BigInteger.valueOf(Long.MAX_VALUE). add(BigInteger.valueOf(Long.MAX_VALUE)); System.out.println(isBiggerThanMaxLong(big3));
source share