We are casting 'obj' to 'Test' and then comparing each of its attributes with 'this' object, and if this comparison is true, we declare that both objects are equal.
This is not making too much sense to me.
All things are lawful, but not all things are profitable.
For those who haven't seen it before, that is a rhetorical device called the Three Great Lies.Somebody's on their way to help already.
The cheque's in the post.
The equals method is easy to understand.
Campbell Ritchie wrote:
Read the two articles and Bloch's book. Now hold your hand on your heart and say the following things:-For those who haven't seen it before, that is a rhetorical device called the Three Great Lies.Somebody's on their way to help already.
The cheque's in the post.
The equals method is easy to understand.
Abhay Bhatt wrote:But it doesn't solve the first question I asked about the purpose of the cast(and neither do any other comment here)
Campbell Ritchie wrote:Right: in the case of Object, there are two ways you can look at things:-
1: There are no fields, so two Objects cannot be different from each other. [list]2: In the absence of further information we cannot assume any two different objects are equal.
Abhay Bhatt wrote:What I get from your comment, is that if, passing an object of class type(compile time object type) 'Test' into the equals method, I talk about in my original query/comment - the compiler would not allow me to access fields of class 'Test' through that object, inside the equals method.
Am I correct in my understanding?
All things are lawful, but not all things are profitable.
I said, in the case of Object, which doesn't have fields. Not Foo.Abhay Bhatt wrote:. . . Why you are saying that there are no fields? . . .
So, the only case Line 13 becomes useful is when 'obj' has 'Test' as its run time object type and 'Test1' as its class type(where 'Test1' is the child class of 'Test').
Junilu Lacar wrote:Your statements about casting to Test and about wierdness indicate that you don't fully understand how casting works.
A cast does not change an object's type. A cast is merely a reassurance to the compiler that the thing you are casting is indeed compatible to the type that you're casting it to. It's like you guaranteeing to a creditor that your friend can indeed pay his loan off. The cast basically tells the compiler, "Trust me on this, I know you only know that this other thing is an Object but I've checked it out and can assure you it's actually an instance of Test."
Abhay Bhatt wrote:
I think the correct statement would be:-
"So, the only case Line 13 becomes useful is when 'obj' has 'Test' as both, its run time object type and class type."
Abhay Bhatt wrote:
So, the below statement stands wrong or invalid in my question:-So, the only case Line 13 becomes useful is when 'obj' has 'Test' as its run time object type and 'Test1' as its class type(where 'Test1' is the child class of 'Test').
I think the correct statement would be:-
"So, the only case Line 13 becomes useful is when 'obj' has 'Test' as both, its run time object type and class type."
I'll be more than happy, to stand corrected, if I am wrong here.
Don't get me started about those stupid light bulbs. |