aspose file tools*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""type int out of range" error on a long variable!" Watch ""type int out of range" error on a long variable!" New topic
Author

"type int out of range" error on a long variable!

Nick Singh
Greenhorn

Joined: Jan 08, 2012
Posts: 11
Never mind, I made a stupid blunder since I don't usually use long and never put an L at the end of the i variable.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

600851475143 is still an int literal. To use it as a long literal, you must append L to it: 600851475143L.
You can officially also use a lowercase l but you should never do that. In some fonts, the difference between l and 1 is not easy to see, so 600851475143l could be seen as both 600851475143L and as 6008514751431. An example:
Without the colouring inside that snippet it would be hard to read the difference between l1 and l2.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

I would further posit that l1, l2, etc. are not fantastic variable names, for similar reasons.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

You have me there. There isn't a problem in the declaration or assignment to those, but using them as arguments, in comparisons or on the right hand side of assignments, can cause confusion. For instance:
With some fonts you may read this as being always true - 11 == 11 after all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "type int out of range" error on a long variable!