1

If i want to initialize a long of 1 or 0 do i need to add L to the end?

long l = 0L;
long k = 1L;

versus

long l = 0;
long k = 1;

Does it matter for low values?

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Steven
  • 319
  • 1
  • 3
  • 7

1 Answers1

6

If i want to initialize a long of 1 or 0 do i need to add L to the end?

Only if the value is larger than will fit in an int. Without the L (or l, but don't use that), the number is an int.

Does it matter for low values?

Not at all. Java's int-to-long conversion is well-defined, and works across the int range.

That doesn't mean that doing so is wrong in any way, of course. You might be doing it for clarity's sake, for instance.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875