• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wrapper dual behavior

 
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


output

Line 1 : true
Line 2 : false

Why So??
 
Ranch Hand
Posts: 185
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because it and ig have different values?
If you set them both to 128 then it will still be false.
If both variable have a value lower 128 and larger than -129 then they both will reference the same object for saving memory (K & B page 246 ). That is the reason for ip==ii resulting in true for a value of 12.

John
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe because 128 is <> of 129: O.o

And yes, if pass 129 you leave the "int" zone code! [=
 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks john.

By the way it didn't get what herbet trying to say

Hebert Coelho
Maybe because 128 is <> of 129: O.o

And yes, if pass 129 you leave the "int" zone code! [=



can anyone simplify?

 
John Stark
Ranch Hand
Posts: 185
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think '128 is <> of 129' means: 128 != 129. So because it = 128 and ig = 129 it == ig returns false.
'if pass 129 you leave the "int" zone code!' should probably mean leave the "byte" zone'? A variable of type byte can store values from -128 to +127 and this is the range in which two Integer objects are the same (== returns true) if their values are equal. If you move out of this zone the two Integer objects are different even if their values are the same.

John
 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i get it now .


thanks john
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic