Created
July 4, 2013 03:25
-
-
Save onelittlenightmusic/5924699 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
import java.lang.reflect.ParameterizedType; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
public class Main { | |
/** | |
* @param args | |
*/ | |
private List<String> list; | |
private Set<Integer> set; | |
private Map<String, Long> map; | |
public static void main(String[] args) { | |
System.out.println("Hello world!"); | |
ParameterizedType listPt; | |
try { | |
listPt = (ParameterizedType) Main.class.getDeclaredField("list") | |
.getGenericType(); | |
System.out.printf("list: %s\n", | |
listPt.getActualTypeArguments()[0].toString()); | |
ParameterizedType setPt = (ParameterizedType) Main.class | |
.getDeclaredField("set").getGenericType(); | |
System.out.printf("set: %s\n", | |
setPt.getActualTypeArguments()[0].toString()); | |
ParameterizedType mapPt = (ParameterizedType) Main.class | |
.getDeclaredField("map").getGenericType(); | |
System.out.printf("map: %s, %s\n", | |
mapPt.getActualTypeArguments()[0].toString(), | |
mapPt.getActualTypeArguments()[1].toString()); | |
} catch (NoSuchFieldException | SecurityException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment