wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes compare short-values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compare short-values " Watch "compare short-values " New topic
Author

compare short-values

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I have to short-values:

something like this returns false:



I guess, I know the difference of equals and identity? But can someone explain it in this scenario.


nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
Okay I guess, I know the difference:

1==1 returns false, because e is identically not i

1.equals(1) returns true, because the value of e is equal of i.



Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816



Well, How did you check it? Did you able to compile it (with short primitive references)?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Vijitha is right, the code will have compile errors as you cannot call equals() on primitives like short,int....

And i==e returns true.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I used it with Short:

Short i;
Short e;

Using primitive types, if(i==e) returns compiler-failure?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

nimo frey wrote:Using primitive types, if(i==e) returns compiler-failure?


No. That should return true with the code you provided in the OP. But i.equals(e) gives you a compiler error if i and e are primitives.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
Please look at this FAQ. If you had written Short rather than short at the beginning of the post, the answer would have been obvious.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
So when using primitive types, I can use clearly this:



When using Wrapper, I have to use equals instead of "==".

thanks
 
Consider Paul's rocket mass heater.
 
subject: compare short-values
 
Similar Threads
Queries--
"==" and equals()
equals or identity
Very Interesting Question
few questions(topics mixed)