This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Sorry Alan--and I know you're probably as exasperated as I am at this point--but your code supports my assertion, not yours. I'll try one more time to set you straight.
subcl1 and super1 are merely references to objects. The references subcl1 and super1 are what are involved in casting. They are not the objects themselves. The objects are the entities that are created by new. They are NOT affected by casting at all. You do not deal with them directly but access them through the references subcl1 and super1. I'm really sorry if I sound exasperated but I sort of am... [ September 17, 2002: Message edited by: Junilu Lacar ]
ohhhhhh, We're on the same page, we just don't think we are. Oh yeah, I get that the cast doesn't really do anything it's just there to mess you up on the mock ? I had. (I read in a couple of books that it's good practice to put it there so other programmers know you meant to do it - well, if you didn't mean to do it then why did you do it). Same thing occurs if you leave out the cast too!
// again, the cast in the above statement is not needed// and changes absolutely NOTHING at all. // subcl1 and super1 are both references to a // superclass and they now reference // THE SAME OBJECT: Object #2.// In fact, since nothing references Object #1 // at this point, it is now eligible for garbage collection// So at this point you only have one Object: Object #2, a superclass
I couldn't agree more. I'm sorry, I've been studying too much and maybe didn't express myself too well. In my head I'm making a distinction between the variable and the type. I should have made it clear that it is the references and not the Objects that are changing types. The references compile-time type and run-time type are different, Objects stay the same. I just passed scjp 1.4 this morning...And let's just say that this discussion may have gotten me a much needed point, so big big thanks guys!!! [ September 17, 2002: Message edited by: Alan Phillips ]