Last active
August 29, 2015 13:56
-
-
Save mark-jay/8860012 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 ReturningGeneric { | |
| public static class A{} | |
| public static class B{} | |
| @Test | |
| public void method1() { | |
| A a = method2(); // so good so far | |
| B b = method2(); // error here | |
| System.out.println(a + " " + b); | |
| } | |
| private <T> T method2() { | |
| try { | |
| T res = (T) new A(); | |
| return res; | |
| } | |
| catch (ClassCastException cce) { | |
| return (T)new B(); // unreachable statement | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment