I need to add a method in a utility class with some static methods that parses things from a JSON string and returns an array of things.
Problem is that there are various subtypes of these things, so I created this method:
public static <E extends Thing> E[] parseThingsFromJSON(String body) {
return parser.fromJson(body, E[].class);
}
How does the caller tell this method what E is? Or is there a better way to do this?
You need to pass it.
Generics is largely a compile time feature. This means its not available at runtime (with some exceptions)
In this case, to make to make the generic type available at runtime, you have to pass it as an additional argument.