• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

integral literal

 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Just a question regarding integral literals. The Java language specification says that all integral literals are 32 bit values. To indicate a long(64 bit) literal append the suffix L to the literal expression.
Right now i cant see the purpose of this (im sure that theres a really obvious reason that ill just kick myself when i hear). If a integral literal is assigned to a long variable then is this literal not upcast automatically to a long. So why do you need to indicate to the VM using L that the literal is to be a long??
thanks,
john
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main reason I can think of is for readability. It indicates that you know what you are talking about. However, I don't ever use this convention. It DOES seem a bit redundant, doesn't it?
The only other thing that comes to mind is that perhaps the compiler can do some kind of optimization if you indicate that the literal is really a long.
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try putting this line into your code and you'll see why you need the L
long myLong = 123123123123123 ;
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marilyn de Queiroz:
try putting this line into your code and you'll see why you need the L
long myLong = 123123123123123 ;

cheers, now i feel stupid. Had to be somthing obvious
:roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic