Changing Between Types

Objectives

We would like to :
  1. Understand how to convert from one type to another.
  2. Define terms associated with this.

Notes

  • To convince it to compile, we need to cast or typecast from one type to another.
  • By the way, when the compiler does it, we call it coercion.
  • In java we have a numeric type hierarchy:
  • But what happens?
  • In the end, we have to cast, but be careful.