Created
August 23, 2022 09:08
-
-
Save Koboo/026dd541b42ed2a296c38d54370ef9c4 to your computer and use it in GitHub Desktop.
Get class of generic object from java class
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
import java.lang.reflect.ParameterizedType; | |
import java.lang.reflect.Type; | |
public class GenericClass<T> { | |
public GenericClass() { | |
Type superclass = this.getClass().getGenericSuperclass(); | |
Type genericClass = ((ParameterizedType) superclass).getActualTypeArguments()[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment