I'm reading a file that I previously wrote as a HashMap<String,String>. Now, I have to read it again, but it is giving me "warning: [unchecked] unchecked conversion", and it's not compiling.
The line of code causing error:
HashMap<String,String> map_stage = Utils.readObject(staging_area, HashMap.class);
staging_area is a File obj, that is working fine. The warning is lamenting between the HashMap<String,String> type on the left, and HashMap.class on the right
The warning:
required: HashMap<String,String>
found: HashMap
Repository.java:156: warning: [unchecked] unchecked conversion
HashMap<String,String> map_stage = Utils.readObject(staging_area, HashMap.class);
^
This is Utils.readObject:
/** Return an object of type T read from FILE, casting it to EXPECTEDCLASS.
* Throws IllegalArgumentException in case of problems. */
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());
}
}
^ this method was given to me, so you can assume is correct.
Compiler error:
grader/submit/AGTester.java:90: error: unreported exception IOException; must be caught or declared to be thrown
Main.main(args);
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error