Covariant Return Types

I've been doing some research as to why my example on overriding vs. overloading failed yesterday in lecture. The answer is covariant return types and the fact that support for them was added in J2SE 5.0. It used to be that if a subclass wants to override a method in a superclass, the method signature in the subclass had to be exactly the same as the method signature in the superclass. Now, the return type is allowed to vary... as long as its a subclass of the return type declared in the superclass. Note that the types of parameters must match exactly, otherwise overloading kicks in, not overriding.

I have created a Java program that demonstrates the nuances. You can download it from the Lectures page.
© Kenneth M. Anderson, 2009.