Encapsulate Downcast

A method returns an object that needs to be downcasted by its callers.

Move the downcast to within the method.

Object lastReading() {
  return readings.lastElement();
}

image/svg+xml

Reading lastReading() {
  return (Reading) readings.lastElement();
}