• 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

Wrappers have Constant Pool Too? see here...

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in JAVA 1.5


output-->

Ai==Bi
Ai.Equals-Bi

bI=5
aI=6

Q1.If both reference points to same Object,why aI increment does not increment bI ?
Q2.If both are same, was there a only Object (Integer 5) pointed by aI and bI when they were defined? means Integer constant pool is maintained for autoboxing?
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ajay futuro:
Q1.If both reference points to same Object,why aI increment does not increment bI ?

since the increment is aquivalent to:
aI = new Integer(aI.intValue() + 1);

Q2.If both are same, was there a only Object (Integer 5) pointed by aI and bI when they were defined? means Integer constant pool is maintained for autoboxing?

Yes. Quote from 5.1.7 Boxing Conversion in the Java Language specification

If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.


Please note, that for values outside the range from -128 to 127, it's undefined whether you get the same object or not.
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic