Posted By

leazen on 07/04/06


Tagged

generics instrospection


Versions (?)

Get parametrized type in runtime


 / Published in: Java
 

This code will only work for immediate specialization not something like class B extends A.

  1. class A<T> {
  2.  
  3. Class<T> specializedClass;
  4.  
  5. public A() {
  6. this.specializedClass = (Class<T>) ((ParameterizedType) this.getClass()
  7. .getGenericSuperclass()).getActualTypeArguments()[0];
  8. }
  9.  
  10. }

Report this snippet  

You need to login to post a comment.