Skip to content

Instantly share code, notes, and snippets.

@DarkSeraphim
Last active December 5, 2017 18:03
Show Gist options
  • Save DarkSeraphim/5b12828577f913f68999a2fb955fc5b6 to your computer and use it in GitHub Desktop.
Save DarkSeraphim/5b12828577f913f68999a2fb955fc5b6 to your computer and use it in GitHub Desktop.
public class Main {
public static void foo(String s) {
System.out.println("Got me a String!");
}
public static void foo(Object s) {
System.out.println("Got me an Object!!!");
}
public static <T> void handle(T t) {
foo(t);
}
public static void main(String... args) {
handle("Hello");
}
}
public class Main {
class Foo {}
class Bar extends Foo {}
public static void foo(Foo s) {
System.out.println("Got me a Foo!");
}
public static void foo(Bar s) {
System.out.println("Got me a Bar!!!");
}
public static void foo(Object s) {
System.out.println("Got me an Object!!!");
}
public static <T extends Foo> void handle(T t) {
foo(t);
}
public static void main(String... args) {
Object o = new Bar();
handle(o);
handle((Bar) o);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment