0

Possible Duplicate:
get type of a generic parameter in java with reflection
Java Generics Reflection: Generic field type of subclass

here's the thing. I have this code and I need to somehow get the generic information from the object.

Class A {
   public static String getGenericType(Object o) {
      ...
   }

   public static void main(String[] args) {
      ArrayList&ltInteger&gt list = new ArrayList&ltInteger&gt();
      getGenericType(list); //this should return "Integer"
   }
}

I know you can get generic type from Field (Class.getField), but this is something different. Anybody knows how to get it done? Thanks in advance.

Have a nice day

Community
  • 1
  • 1
peto1234
  • 369
  • 5
  • 11

1 Answers1

3

Yep, type erasure means that you don't get to know what's inside of <> at run-time.

Ryan Ransford
  • 3,224
  • 28
  • 35