This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from Dan's exam - ClassCastException

 
Junilu Lacar
Bartender
Pie
Posts: 7320
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Alan Phillips
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alan Phillips:
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!!!

Congratulations, Alan! Best of luck on your next step
 
Junilu Lacar
Bartender
Pie
Posts: 7320
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congratulations, Alan!
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congratulation Allan. How was the exam? Any clues, advises....
 
Alan Phillips
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barkat! Thanks for your posts, check out my post under results!
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congrats Alan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic