Skip to content

Instantly share code, notes, and snippets.

@NickHeiner
Created March 13, 2012 21:58
Show Gist options
  • Save NickHeiner/2032032 to your computer and use it in GitHub Desktop.
Save NickHeiner/2032032 to your computer and use it in GitHub Desktop.
Java compile time run time overloading
public class Main {
static class Root {}
static class Sub extends Root {}
public static void main(String[] args) {
foo(new Sub());
Root r = new Sub();
foo(r);
}
static void foo(Sub s) {
System.out.println("sub");
}
static void foo(Root r) {
System.out.println("root");
}
}
/* This prints:
sub
root
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment