Creating a Type object corresponding to a generic type

Posted by Alexey Romanov on Stack Overflow See other posts from Stack Overflow or by Alexey Romanov
Published on 2010-06-07T11:34:16Z Indexed on 2010/06/07 11:42 UTC
Read the original article Hit count: 241

Filed under:
|

In Java, how can I construct a Type object for Map<String, String>?

System.out.println(Map<String, String>.class);

doesn't compile. One workaround I can think of is

private Map<String, String> dummy() { throw new Error(); }
Type mapStringString = Class.forName("ThisClass").getMethod("dummy", null).getGenericReturnType();

Is this the correct way?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics