I have problem with the Long
data type when I run this command:
Long nanos = 3 * 1000000000
println nanos
It prints out -1294967296
, not 3000000000
, and I dont know why.
I read on this page that Long is enough. So what is wrong ?
You must mark your 2nd constant as long, otherwise it's considered an integer which overflows. Use:
Long nanos = 3 * 1000000000L
You need to add a suffix to literals to imply that they are long values. Otherwise they are interpreted as int.
Long nanos = 3 * 1000000000L;
More info about this here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With