Created
March 15, 2012 23:37
-
-
Save electrum/2047669 to your computer and use it in GitHub Desktop.
Java Covariant Return
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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