Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot assign a value to long datatype  RSS feed

 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,

I am using eclipse for development and when assign variable "milliseconds" to long and declare its value to "1299439723234", i see a error "The literal 1299439723234 of type int is out of range ". What can be the issue?

long milliseconds = 1299439723234;


Thanks
Aditya
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The literal that you are using to set, is an int literal. To create a long literal use the "L" at the end of it.



Henry
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And never, ever use a lowercase l - always use an uppercase L. The lowercase looks too much like a 1 in many fonts, so you will get confused. For example:
Without the colouring of line 2, do you see any real difference between lines 1 and 2? There certainly is one: line 1 gives value1 a value of 1l (one), line 2 gives value2 a value of 11 (eleven). Line 3 can only be read in one way.
 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should really use the L for all numbers you wish to be longs, eg 1L as rob showed above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!