Created
June 3, 2016 22:05
-
-
Save NaanProphet/ae513558c97f410891fa2e863c504ae2 to your computer and use it in GitHub Desktop.
Java obtain generic type at runtime
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
// This statement is magic | |
// If you declare it: Set<String> getMyGeneric; it returns java.lang.String | |
final Class<?> genericClazz = (Class<?>)((ParameterizedType) getClass().getDeclaredField("getMyGeneric").getGenericType()).getActualTypeArguments()[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment