This week's book giveaway is in the Security forum.
We're giving away four copies of Securing DevOps and have Julien Vehent on-line!
See this thread for details.
Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compare short-values  RSS feed

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Saloon Keeper
Posts: 4041
47
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Well, How did you check it? Did you able to compile it (with short primitive references)?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used it with Short:

Short i;
Short e;

Using primitive types, if(i==e) returns compiler-failure?
 
Vijitha Kumara
Saloon Keeper
Posts: 4041
47
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 57909
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when using primitive types, I can use clearly this:



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

thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!