Skip to content

Instantly share code, notes, and snippets.

@Koboo
Created August 23, 2022 09:08
Show Gist options
  • Save Koboo/026dd541b42ed2a296c38d54370ef9c4 to your computer and use it in GitHub Desktop.
Save Koboo/026dd541b42ed2a296c38d54370ef9c4 to your computer and use it in GitHub Desktop.
Get class of generic object from java class
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