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<Integer> list = new ArrayList<Integer>();
      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

0

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.