Last active
February 21, 2017 06:27
-
-
Save koher/4484ac72995a92a29a056d9f6401eec8 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 GenericReturnType { | |
public static void main(String[] args) { | |
// 引数の型は `Object` なので戻り値から型パラメータが推論される | |
Integer n = id(42); | |
String s = id("xyz"); | |
System.out.println(n); | |
System.out.println(s); | |
} | |
static <T> T id(Object x) { | |
return (T)x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment