I am getting an error in the following line - Utils.read(new File("asd"),Map<String,Commit>.class);
The error is cannot select from parameterized type
The readObject function is declared as public static <T extends Serializable> T readObject(File file, Class<T> expectedClass)
How do I pass a Map of type <String, Commit> in this case
The complete definition of readObject function: <br>
public static <T extends Serializable> T readObject(File file,
Class<T> expectedClass) {
try {
ObjectInputStream in =
new ObjectInputStream(new FileInputStream(file));
T result = expectedClass.cast(in.readObject());
in.close();
return result;
} catch (IOException | ClassCastException
| ClassNotFoundException excp) {
throw new IllegalArgumentException(excp.getMessage());
}
}<br>
Is instead of the above code to read the object, I use the following code :
Object readObject(File f) {
byte[] arr = Utils.readContents(f);
ByteArrayInputStream i = new ByteArrayInputStream(arr);
try {
ObjectInputStream s = new ObjectInputStream(i);
Object o = s.readObject();
s.close();
i.close();
return o;
} catch (IOException | ClassNotFoundException c) {
System.out.println("IOException");
return null;
}
}<br>
and call (HashMap<String, Commit>) readObject(Utils.join(dir, "commits"));
Then it works perfectly. The Commit is serializable and internally has a HashMap. This is coming null if I use the earlier code, but it's coming alright with this code. The earlier code I am calling like. ``