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
Map<String, String> dummy() { throw new Error(); }
Type mapStringString = Class.forName("ThisClass").getMethod("dummy", null).getGenericReturnType();
Is this the correct way?
Is a slightly less ugly hack..
As Tom Hawtin suggests, you could implement the methods yourself:
returns the same values as the other approach for the methods declared in
ParameterizedType. The result of the first approach even.equalsthis type. (However, this approach does not override toString, equals and so on, so depending on your needs, the first approach might still be better.)