java - unchecked cast warning - how to avoid this? -
this question has answer here:
- how address unchecked cast warnings? 24 answers
i'm getting "type safety: unchecked cast object arraylist" warning on line readobject(), in code snippet:
// read event list theeventarraylist = new arraylist<event>(); string filename = "eventdata.dat"; fileinputstream fis; try { fis = openfileinput(filename); objectinputstream ois = new objectinputstream(fis); theeventarraylist = (arraylist<event>) ois.readobject(); fis.close(); }
event
simple class comprised of strings, calendars, booleans, , ints. arraylist
written using objectoutputstream in mirror image operation above. application code used in executed many times day on month no failures, compiler warning bothers me , don't want suppress if can "checked" properly.
suppress it. other alternative cast arraylist, everywhere else in code have deal untyped arraylist , casting on read. there no harm in suppressing in situation.
Comments
Post a Comment