• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Equals and == (again)

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, why in the code bellow the result is true true? In K&B, pg.236 Chapter 3 we read that two instances of the some wrapper objects (Character from \u0000 to \u007f, Boolean, Short and Integer from -128 to 127) will always be == when their primitive values are the same. But, this is valid for Long either?

 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello, why in the code bellow the result is true true? In K&B, pg.236 Chapter 3 we read that two instances of the some wrapper objects (Character from \u0000 to \u007f, Boolean, Short and Integer from -128 to 127) will always be == when their primitive values are the same. But, this is valid for Long either?



The specification states that "Character from \u0000 to \u007f, Boolean, Short and Integer from -128 to 127" are cached, and hence, will be "==", via boxing when their primitives values are the same.

The specification does *not* state, that primatives values outside of this range, nor other types, must not be cache. The JVM from Sun does indeed cache a range for Long too, but there is nothing is the specification that states that it must do so.

Henry
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic