java - Implementing List instead of ArrayList while using generics instead of raw types -
after going through many posts , suggestions, have found instead of using concrete implementation such arraylist, should use list instead, allow flexibility between different implementations of list interface. far, have seen many programmers suggest following line of code:
list list = new arraylist();
however, give warning in compiler using raw types list , arraylist , should parameterized.
synonymous these warnings, have found several posts telling me raw types should never used , should take advantage in using generics java offers conveniently.
personally, trying implement class acts table requiring 2 dimensional list structure arraylists being used internally. trying implement following lines of code:
list<list> table; table = new arraylist(); table.add(new arraylist());
envisioned in head, table structure should able hold multiple variable types such raw data types along string variable type. have tried implement generics such using
list<list<object>> table = new arraylist<arraylist<object>>();
but have received many errors , hence failed far.
i relatively new programming, pursing computer science major, forgive me if have horrible misunderstanding of lines of code have exemplified above.
thank you.
you want this:
list<list<foo>> table = new arraylist<list<foo>>(); table.add(new arraylist<foo>())
where foo
type stored in table.
you want generic parameter of type , value same.
Comments
Post a Comment