Here you go heroes: int x = 10; float f = 10.0f; x==f; explanation: x will be promoted to a float for the comparison and they will be the same value when that occurs. Is this right? I thought == meant "the same space in memory". Thanks for clarifying.
you must distinguish between primitive and reference type. == compares the space in memory for reference types and the value for primitive types. int a=0,b=3; a==b; // the value of a and b are compared for equality Object o1=new Object(); Object o2=new Object(); o1==o2; // the references of o1 and o2 are compared for equality, in this case the test fails because we have 2 different objects HIH
If you read any of the books on comparison you will see that in any comparison of numeric values the smaller data type will be automatically be promoted to the larger before the comparison. Also you said "I thought == meant "the same space in memory" ....NOT for primitives, that is for objects.
Joined: Jan 18, 2001
Thanks for the clarification. So... there are books on comparison huh?