L means it is a long literal. 1000 is an int. It will automatically
be promoted to long.
see http://mindprod.com/jgloss/literal.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
>> I found in some code the following 'sleep(1000L)': I'd just
>> like to know what padding an 'L' after 1000 does. What
>> would be the difference with a simple 'sleep(1000)' ?
> L means it is a long literal. 1000 is an int. It will automatically
> be promoted to long.
Clarification: Roedy does not mean that all int values
are automatically promoted to long, and indeed they are not.
But when the Java compiler sees `sleep(1000)' it first tries
to find a method named sleep that takes an int argument. If
no such method exists Java will look for alternatives. In
this case (assuming sleep is Thread.sleep), it finds that
there *is* a method named sleep that takes a long argument.
Since Java knows how to promote an int to a long, it makes
the conversion and calls the long-accepting sleep method.
By using `sleep(1000L)' in the first place, the writer
saved the compiler from all this rummaging around (not very
important) and also made it plain to people reading the code
that the call was to a method taking a long argument -- that
is, the writer saves *you* from the same rummaging around
that the compiler goes through.
To experiment with how this works, ponder the following
class and predict its output, then compile it and check
your predictions:
class Promote {
void m(double d) { System.out.println("double: " + d); }
void m(long l) { System.out.println("long: " + l); }
// void m(int i) { System.out.println("int: " + i); }
void m(short s) { System.out.println("short: " + s); }
void m(Object o) { System.out.println("object: " + o);
public static void main(String[] unused) {
m( (byte)1 );
m( (short)2 );
m( 3 );
m( 4L );
m( 5.0f );
m( 6.0 );
m( new Integer(7) );
m( "eight" );
}
}
For extra credit, predict what would happen if you removed
the // from the fourth line (and check your prediction).

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
Eric Sosman - 30 Jul 2007 14:20 GMT
> [...]
> To experiment with how this works, ponder the following
> class and predict its output, then compile it and check
> your predictions:
> [...]
Well, I made a fine mess out of that one, didn't I? Try
this code instead, and accept my apologies for any confusion:
class Promote {
static void m(double d) {
System.out.println("double: " + d); }
static void m(long l) { System.out.println("long: " + l); }
// static void m(int i) { System.out.println("int: " + i); }
static void m(short s) {
System.out.println("short: " + s); }
static void m(Object o) {
System.out.println("object: " + o); }
public static void main(String[] unused) {
m( (byte)1 );
m( (short)2 );
m( 3 );
m( 4L );
m( 5.0f );
m( 6.0 );
m( new Integer(7) );
m( "eight" );
}
}

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
Roedy Green - 30 Jul 2007 15:46 GMT
> Well, I made a fine mess out of that one, didn't I? Try
>this code instead, and accept my apologies for any confusion:
For yet another stab at explaining it, please see
http://mindprod.com/jgloss/overload.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com