Last active
December 14, 2015 19:39
-
-
Save karadaisy/5137971 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class DynamicDispatch { | |
interface GeometricValue { | |
void intersects(GeometricValue v); | |
} | |
static class Point implements GeometricValue { | |
@Override | |
public void intersects(GeometricValue v) { | |
throw new UnsupportedOperationException(); | |
} | |
public void intersects(Point p) { | |
System.out.println("Testing intersection with Point"); | |
} | |
public void intersects(Line l) { | |
System.out.println("Testing intersection with Line"); | |
} | |
} | |
static class Line implements GeometricValue { | |
@Override | |
public void intersects(GeometricValue v) { | |
throw new UnsupportedOperationException(); | |
} | |
} | |
public static void main(String args[]) { | |
new Point().intersects(new Line()); // => Testing intersection with Line | |
GeometricValue p = new Point(); | |
GeometricValue l = new Line(); | |
p.intersects(l); // => throws UnsupportedOperationException | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment