Created
June 10, 2015 02:17
-
-
Save taichi/855274c24a99db72545b to your computer and use it in GitHub Desktop.
This file contains 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 ReturnTypeOverload { | |
public static void main(String[] args) { | |
Long lv = getValue(); | |
System.out.println(lv); | |
String sv = getValue(); | |
System.out.println(sv); | |
} | |
// public static Long get() { | |
// return 30L; | |
// } | |
// | |
// public static String get() { | |
// return "33"; | |
// } | |
@SuppressWarnings("unchecked") | |
public static <T> T getValue(T... dontset) { | |
Class<?> type = dontset.getClass().getComponentType(); | |
if (Long.class.equals(type)) { | |
return (T) Long.valueOf("30"); | |
} | |
if (String.class.equals(type)) { | |
return (T) "33"; | |
} | |
throw new IllegalStateException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment