• Post Reply Bookmark Topic Watch Topic
  • New Topic

References  RSS feed

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I know that references have some bitpattern corresponding to the object it refers.
what is the bitpattern stored in the references with null value(ex:String s=null)?Will it be the same for all type of references with null value?
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like something I would hope to never know. The wealth of such things are among the reasons I prefer Java to C. What would you like to do based on this information?
 
vinuharan haran
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm preparing for SCJP.I came across the code given below

Output is :equal
As == operator compares the bitpattern stored in references,i'm
just curious to know abt null references.....
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely it's a 0, but I guess that isn't really specified by the specification, but open to be implemented by the VM as preferred by the vendor.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
== does not compare the "bit pattern" of a reference. There is no requirement that references have a "bit pattern". Unlike C pointers, references are entirely opaque; their representation is completely unknowable.

That said, null is null. For any two null references a and b, of any type,

(Object) a == (Object) b

is true (I added the casts because the compiler won't necessarily let you compare all possible references without them.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!