The situation I'm trying to create is as follows:
I have a base class containing a static template method that gets a ResultSet populated with a query in the database and returns a list with the correct results.
I have some classes that stem from the above, which represents each table from the database, and they all have a constructor that gets a ResultSet and builds an object.
The code I wrote is:
public class TableBase { public static <T extends TableBase> List<T> getResults(ResultSet p_Rs) throws SQLException, InstantiationException, IllegalAccessException { List<T> v_Table = new ArrayList<T>(); T v_TB = null; while(p_Rs.next()) v_Table.add(new T(p_Rs)); return v_Table; } }
The error I received is: Cannot instantiate the type T
It is clear to me that the compiler must “know” that all child classes implement a constructor that receives the ResultSet variable, but I cannot create an “abstract constructor”.
Does anyone know how to solve this?
Thanks to everyone in advance.
source share