== is check object Reference equality so how can we use on primitive type veriable
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, January 29, 2008 02:43 PM

1)ob1==ob2

2)int i=10
if(i==5)
{
System.out.println("stop");

}
else
{
System.out.println("start");

}

Re: == is check object Reference equality so how can we use on primitive type variable

Posted By:   Stephen_McConnell  
Posted On:   Tuesday, January 29, 2008 04:10 PM

One has to understand what it means when you do a ==.


You are looking at the value that is in that memory location. In the case of a primitive, the value in that memory location is the value of the primitive. However, in the case of an object, you are looking at a pointer to the object. When you do an == on an object, you are determining if the pointer to the object is the same. If not, then you are not looking at the same object.


Hope this helps.


Stephen McConnell

About | Sitemap | Contact