Home > OS >  Type Casting doesn't work for my variable
Type Casting doesn't work for my variable

Time:11-25

Hello I am fairly new to java! I really struggle to solve this error and I can't finde anything on the internet. if I do: long test = (long) (2147483647 1); it sets test to an int even though I used long. why?

I tryed it using max int value but still it doesn't worked. long test = (long) (Integer.MAX_VALUE 1);

CodePudding user response:

cast then add

long test = (long) (2147483647)   1;
System.out.println(test);

2147483648

Otherwise you are adding two ints then casting

  •  Tags:  
  • java
  • Related