edu.pdx.cs399J.j2se15
Class CovariantReturns

java.lang.Object
  extended by edu.pdx.cs399J.j2se15.CovariantReturns

public class CovariantReturns
extends Object

This class demonstrates covariant returns in JDK 1.5. The Java compiler allows an overriding method to change the method's return type to be a subclass of the overriden method's return type. However, you have to be extra careful when using covariant returns with legacy code. If someone else overrides a method and doesn't change the return type, their code will not compile.

Since:
Winter 2004
Author:
David Whitlock

Constructor Summary
CovariantReturns()
           
 
Method Summary
static void main(String[] args)
          A main class that clones some animals.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CovariantReturns

public CovariantReturns()
Method Detail

main

public static void main(String[] args)
A main class that clones some animals. Note that we don't need to cast the result of the clone method.



Copyright © 2000-2009 Portland State University. All Rights Reserved.