Skip to content

Instantly share code, notes, and snippets.

@electrum
Created March 15, 2012 23:37
Show Gist options
  • Save electrum/2047669 to your computer and use it in GitHub Desktop.
Save electrum/2047669 to your computer and use it in GitHub Desktop.
Java Covariant Return
package javatest;
public class CovariantReturn
{
private static class NumberNode
{
public Number get()
{
return 13;
}
}
private static class IntegerNode
extends NumberNode
{
@Override
public Integer get()
{
return 42;
}
}
public static void main(String[] args)
{
NumberNode node = new IntegerNode();
Number n = node.get();
Integer i = ((IntegerNode) node).get();
System.out.println(n);
System.out.println(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment