...there is Double is comparing with Integer ? will it not produce error..as it written in some eg. of K&B
but K&B also wrote that it will produce compiler error when we compare differnt objects ?
They have to be explicitely casted to a common base class. (Or you can cast one, and let Java implicitely cast the other)
Originally posted by jas oberai:
Can you just show this with some code from the above example,so that we should not get any compiler error.This == and equals thing really gets confusing at times.Thanks
And BTW, this exercise is kinda pointless. If you need a cast to a common base class, you kinda know the result. The condition will report false -- as there is no way they can be the same reference.
Let me know if this is clear, or if you still have doubts, there are a lot of other things to say about equals and ==, that part might be confusing on K&B at the beginning, but if you try a lot of examples, you will get it!
This explanation is just the basic you MUST understand in order to grasp the other concepts.