arraylist - How to add items to a list of type List<? extends Object> -


i have list of type -

list<? extends object> = new arraylist<oracle.jbo.domain.date> (); 

but when try add items list compile time error - step -

a.add( new oracle.jbo.domain.date() ); 

will throw following error -

error(183,22):  cannot find method add(oracle.jbo.domain.date) 

how add elements list ? appreciated.

thanks

if arraylist contains oracle.jbo.domain.date instances, why saving reference list<? extends object>? using generics in reference should avoided (as can check here) when want insert elements in list. arraylist can contain 1 kind of data so:

list<oracle.jbo.domain.date> = new arraylist<oracle.jbo.domain.date>(); a.add( new oracle.jbo.domain.date() ); 

but if have list<? extends object>, sorry can't insert elements list. in fact compiler has no int kind of list is. different from:

list<object> = new arraylist<object>(); 

in fact in case know can add anything, because extends object. in case of legal assignments:

list<? extends object> = new arraylist<integer>(); list<? extends object> = new arraylist<double>(); list<? extends object> = new arraylist<string>(); 

and compiler doesn't know 1 current case. prevented inserting elements. commonly used make read-only objects.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -