| Author |
== operator
|
Gaurav Pavan Kumar Jain
Ranch Hand
Joined: Mar 19, 2007
Posts: 168
|
|
hi all please let me know the functioning of == operator in refrence of object variable. Please specify example also
|
 |
qunfeng wang
Ranch Hand
Joined: Jan 28, 2005
Posts: 410
|
|
The "==" operator is used to determine if two references refer to the same object when object variables concerned.
|
To be or not to be. It's a question.
|
 |
Saket Barve
Ranch Hand
Joined: Dec 19, 2002
Posts: 224
|
|
The == operator will check for reference equality whereas the .equals method will compare the actual values. In the following code, "Different Reference" will be printed out. Here's a good link.
|
 |
Gaurav Pavan Kumar Jain
Ranch Hand
Joined: Mar 19, 2007
Posts: 168
|
|
|
Thank you for your suggestion
|
 |
Anupam Sinha
Ranch Hand
Joined: Apr 13, 2003
Posts: 1088
|
|
|
By default equals() would also check for reference equality unless it is overridden.
|
 |
sadasiva kumar
Ranch Hand
Joined: Oct 30, 2003
Posts: 84
|
|
Use == operator to compare two primitives,or to see if two references refer to the same object. Remember ,the == operator cares only about the pattern of bits in the variable.The rules are the same whether the variable is a reference or primitive. Example : (1) Comparing two primitives int a = 9; byte b = 9; if( a == b) { // true } (2) Comparing two references Zoom a = new Zoom(); Zoom b = new Zoom(); Zoom c = a; if(a == b) { // false } if(a == c) { // true } if(b == c) { // false } regards SADASIVAKUMAR UTTI SCJP1.4
|
SADASIVAKUMAR UTTI, SCJP1.4
A bend in the road is not the end of the road ... unless you fail to make the turn.
|
 |
 |
|
|
subject: == operator
|
|
|