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

Long Object  RSS feed

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dear friends,

In the above code, when the Long object value exceeds 127 the 'object comparison' condition fails. The condition passes until the number 127. Why is there a limit till 127? I use primitives only for comparison, but just while experimenting i came across this problem.

Request to clarify the issue.

Thanks & Regards,
Vijay
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is some Long objects are cached. This question has come up before like here.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, never use lowercase l to indicate a value is a long. Always use uppercase L. When I first read your code I saw 3,051 and 1,271 instead of the 305 and 127 that you actually wrote. That's because in some fonts there is too little difference between an l and a 1.

The Javadoc pages also used to use a lowercase l, as seen here (Java 1.4). Java 5.0 already fixed that to generate an uppercase L, something that is still present (fortunately) in Java 6.
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Rob/Wouter,

Thank you very much for your help. Really appreciate it. It was very helpful in gaining additional knowledge.

Regards,
Vijay
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!