java - Warning: [unchecked] unchecked conversion -


i facing issue generics here. can please point me missing on in below statements?

1.

warning: [unchecked] unchecked conversion  list<question> qlist = (list) session.getattribute("qlist");                                        ^   required: list<question>   found:    list 

2.

warning: [unchecked] unchecked conversion  list<examschedule> elist = new <examschedule>arraylist();  required: list<examschedule> found:    arraylist 

i don't want supress warnings. suggestions appreciated.

list<question> qlist = (list) session.getattribute("qlist"); 
  1. session.getattribute("qlist"); return instance of type object. need explicitly cast it.

  2. (list) raw type, list<string> generic type , trying cast raw type generic type reference gives warning.

now, if this:

list<question> qlist = (list<question>) session.getattribute("qlist");

the cast runtime check there type erasure @ runtime, there's no difference between list<string> , list<foo> etc.hence error. try (list<?> list) type conversion verifies object list without caring types held within.

list<examschedule> elist = new <examschedule>arraylist(); 

that syntax error.it should arraylist<examschedule> , not <examschedule>arraylist.

suggestions :

list<?> qlist = (list<?>) session.getattribute("qlist"); list<examschedule> elist = new arraylist<examschedule>(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -