The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tempusfugit (144) [Avatar] Offline
9.4.2 Implementing interfaces and casting p.254 - "upcast"

"When the conversion between the types cannot fail, it is called an upcast."

True, upcasts cannot fail but they are called upcasts because ...

Thinking in Java, Chapter 6: Why Upcasting?

"The reason for the term is historical, and based on the way class inheritance diagrams have traditionally been drawn: with the root at the top of the page, growing downward. ... Casting from a derived type to a base type moves up on the inheritance diagram, so it’s commonly referred to as upcasting. Upcasting is always safe because you’re going from a more specific type to a more general type. ... You can also perform the reverse of upcasting, called downcasting, but this involves a dilemma ...