javabeans - Java: Trouble with wildcards/generics -
this question has answer here:
i struggling using wildcards/generics. i'm trying create filemanager utility class can accept custom java beans , write read/write bean file. give example imagine have interface called data implemented recipedata , demographicdata. i'm using super csv convert csv file java bean. here read method based on tutorial code found super csv.
public interface data { method declarations } public class recipedata implements data { class stuff goes here } public class demographicdata implements data { class stuff goes here } final public class filemanager { public static void parsecsvfile(string filename, cellprocessor[] processors, string[] namemappings, list<? extends data> container) { icsvbeanreader beanreader = null; try { beanreader = new csvbeanreader(new filereader(filename), csvpreference.standard_preference); data data; while((data = beanreader.read(data.class, namemappings, processors)) != null ) { container.add(data); } } { if (beanreader != null) { beanreader.close(); } } } } currently, i'm getting following error:
the method add(capture#1-of ? extends data) in type list not applicable arguments (data)
i'm not sure i'm doing possible. idea is, container passed can of type recipedata or demographicdata. think 1 problem data should of 2 types.
can give feedback on how potentially fix or if it'll work?
edit: i'm not sure possible.
instead of using wildcard list<? extends data> container, use list<data> container.
Comments
Post a Comment