Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assignment operator : doubt.......

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
char c = 65;
double d = 10;
if(c==d)


i doubt how two different type are compared. Though it is a basic doubt i want some one to explain me about this....
 
Sakthi Kani
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

U can compare the two different type.
If both r compatible it returns true.



So, in your code char and double r incompatible.

hope u got it.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thank u for ur reply

is the following code legal???

Object a = "hello";
String b = "hello";
if(a == b)
System.out.println("equal");
else
System.out.println("not equal");
 
Sakthi Kani
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi paramesh




This is legal it gives the result as equal.Both object reference has the same hashcode, because both value r same.

Check the following code to understand



Now in this case, it has differnet hashcode.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i say on using == the both operands should belong to the same hierarchy..
 
Sakthi Kani
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

whenever u get doubt, first u try it out with small sample program.
Even then, u can't understand then post it. Because trying yourself will help u more than others explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic