-1

This is not new, but I wonder how come java can assign something like, 1L to long datatype.

private static final long serialVersionUID = 1L;

where the definition of long data type is,

long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.

From : Oracle, Java primitive datatypes

TeaCupApp
  • 11,316
  • 18
  • 70
  • 150

1 Answers1

3

The L indicates that it is a long. In other words, 1 is an int whereas 1L is a long. It is specified in the Java Language Specification #3.10.1:

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int.
The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

assylias
  • 321,522
  • 82
  • 660
  • 783