0

This is my generic construtor

public TreeContainer(Class<T> type, Object parentPID, List<Object> childrensPID) throws IllegalArgumentException {
    super(type);
    this.parentPID = parentPID;
    this.childrensPID = childrensPID;
}

This is my bean (with getter setter)

public class DirectoryBean implements Serializable {
      private long id;
      private String name;
      private DirectoryBean parent;
      private List<DirectoryBean> childrens;    
}

I create a new Tree Container like this

TreeContainer<DirectoryBean> treeContainer = new TreeContainer<DirectoryBean>(DirectoryBean.class,"parent", "childrens" );

But the "childrens" parameter is illegal, how can i pass the list params in this situation


Probably would be sufficient to change it to ? extends Object. However, the purpose of using generics here is to limit the range of data types. You'd be better off doing something like:

? extends BeanBaseObject

4

2 回答 2

1

Your constructor expects this

List<Object> childrensPID

but you are passing a String "childrens". You can get around it by putting it in a list.

List<Object> childrens = new ArrayList<Object>();
childrens.add("childrens");
new TreeContainer<DirectoryBean>(DirectoryBean.class,"parent", childrens );
于 2012-04-17T15:16:25.110 回答
1

可能足以将其更改为? extends Object. 但是,这里使用泛型的目的是限制数据类型的范围。你最好做类似的事情:

? extends BeanBaseObject

于 2012-04-17T15:13:43.730 回答