Skip to content

Instantly share code, notes, and snippets.

@nmaier
Created August 18, 2013 00:41
Show Gist options
  • Save nmaier/6259373 to your computer and use it in GitHub Desktop.
Save nmaier/6259373 to your computer and use it in GitHub Desktop.
package nmaier.so_der;
public class Program {
static class Piece {}
static class Man extends Piece{}
static class Square {
private Piece p_;
public Square(Piece p) {
p_ = p;
}
public Piece getPiece() {
return p_;
}
}
static void print(Piece piece) {
System.out.println("Piece");
}
static void print(Man man) {
System.out.println("Man");
}
static void print(Square square) {
print(square.getPiece());
}
public static void main(String [] args) {
Square s = new Square(new Man());
print(s); // Prints "Piece"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment