This may be a dumb question but I really need to find a solution for it.
This is my code:
public static <J> J[]fromJson(Class<?> classType, String fileLocation){
try {
Gson gson = new Gson();
J[] data = (J[]) gson.fromJson(new FileReader(fileLocation), classType[].class);
return (J[]) data;
} catch (Exception oe) {
System.err.println("Exception: " + oe.getMessage());
return null;
}
But Java does not allow the decalration as classType[].class (5th line). and I need to call my function as fromJson(People.class,"file.json"). I try to be generic with this method, so I can use the same method for different class types that I need from the Json file.
Can someone show me what I did wrong ?
Thank you very much.