Last active
December 5, 2017 18:03
-
-
Save DarkSeraphim/5b12828577f913f68999a2fb955fc5b6 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 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"); | |
| } | |
| } |
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 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