I googled around and I couldn't really understand how to do this. I'm trying to add items to a list like this: List<?>. My code looks something like this:
public class Test {
private List<?> list;
public Test(List<?> useThisList) {
this.list = useThisList;
}
public void add(Object add) {
this.list.add(add); // this won't compile
}
}
However, as commented, that code won't compile. I've tried to change it to something like:
public void add(? add) {
this.list.add(add);
}
But that won't compile for more obvious reasons. Does anyone know what I need to change this to to make it function properly? Thanks in advance!
By the way, when it does work, you should be able to do this:
List<String> list = new ArrayList<String>();
new Test(list).add("hello");
addto it? Perhaps yourTestclass should be generic...