java - unchecked cast warning - how to avoid this? -


this question has answer here:

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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -