Java Generics语法设置器

时间:2016-04-14 16:46:32

标签: java generics

我有这两个类,我需要在父类的子类filds中初始化。

public class A {

    protected LazyFacade<E> list;
    protected LazyDataModel<E> model;
    protected MyObject myObject;

    protected LazyDataModel<E> buildModel() {
            lazyModel = new LazyDataModel<E>() {
                public List<E> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
                    List<E> resultList = null;
                    try {
                        setRowCount((int) list.countObjects(myObject, filters));
                        resultList = list.listObject(myObject, first, pageSize, sortField, sortOrder, filters);
                    } catch (PersistenceException e) {
                    }
                    return resultList;
                }
            };
        return lazyModel;
    }
    //getters setters
}

public class B extends A {

    public B() {
        this.list = new LazyFacade<OtherClass>();   **//is it correct way to instantiate the list???**
        this.myObject = getObjectInDataBase();
        this.model = buildModel();                  **//the model must have the same class of LazyFacade, in this case OtherClass.
                                                    //How could i do it?**
    }
}

1 个答案:

答案 0 :(得分:0)

尝试将public class A {更改为public class A<E> {