• Post Reply Bookmark Topic Watch Topic
  • New Topic

long Literals  RSS feed

 
Abhishek Sarkhel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it mandatory to use l or L as suffix in case of declaration of long Literals.I am not getting any error for following two codes there for i am confused.

**************
1st code
**************
class Long
{
public static void main(String[] args)
{
long jo=110599;
long so=0XFFFF;
System.out.println("jo="+jo);
System.out.println("so="+so);
}
}

**************
2nd code
**************

class Long
{
public static void main(String[] args)
{
long jo=110599L;
long so=0XFFFFl;
System.out.println("jo="+jo);
System.out.println("so="+so);
}
}

Thanks in advance.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is mandatory. If you don't use the L suffix, then what you have is an integer literal instead. Of course an int can be assigned to a long variable with no problem, so the only time you will have a compile error is when the value of the literal is outside the range of values of ints. Which in your example they aren't.
 
Abhishek Sarkhel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,my confusion is now clear.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try to use L instead of l. The latter looks to much like a 1 in some fonts. Compare:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!