I have the following method signature, how do i convert it to be a template.
public static JSONContainer getMappedRootObject(JSONContainer clazz, String filename) {
...
JSONContainer container = new Gson().fromJson(br, JSONContainer.class);
return container;
}
This is what i came up with, is this right?
public static <T extends Object> T getMappedRootObject(Class<T> clazz, String filename) {
T container = new Gson().fromJson(br, clazz);
return container;
}
If in your JSONContainer implementation, the “JSONContainer clazz” parameter is an instance of the target object, you may do the following: