incubator-empire-db-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <>
Subject Stupid generics question (possibly)
Date Sun, 24 Jul 2011 12:00:20 GMT


This might be a stupid question possibly but I just don't feel like investigating myself.


I have introduced a new simple helper class called BeanResult to simplify queries for a list
of POJO's a bit.

I looks roughly like this:


public class BeanResult<T extends Object> extends ArrayList<T>


    private DBCommand cmd;

    private Class<T> type;


    public BeanResult(Class<T> type, DBCommand cmd)


        this.type = type;

        this.cmd = cmd;



    public int fetch(Connection conn, int maxItems)



        DBReader reader = new DBReader();

        try {

            // Open and Read

  , conn);

            reader.getBeanList(this, type, maxItems);

            return size();


        } finally {






In order to use it, I must write the following:


BeanResult<SampleBean> result = new BeanResult<SampleBean>(SampleBean.class, cmd);


What I don't like is, that I have to pass the SampleBean.class in the constructor.

I would rather just write:


BeanResult<SampleBean> result = new BeanResult<SampleBean>(cmd);


This is beause the getBeanList uses type.newInstance() to create new Instances of the bean.


Does anyone know whether and how to determine the Class from T or another option to get rid
of this extra parameter.

I have checked the code in under the EMPIREDB-99 branch.





  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message