I like to create a view of database table classes in java. A column is designed as a general class so that it can handle all the different types of data columns that may be available.
public class TableColumn<T> { ... }
The table has 0 ... n TableColumns, so my table class looks like this:
public class Table { protected ArrayList<TableColumn<T>> columns = new ArrayList<TableColumn<T>>(); ... }
The idea is to add columns as follows.
Table t = new Table(); t.addColumn(String.class); t.addColumn(Integer.class); t.addColumn(Date.class); t.addColumn(String.class);
And then I can manipulate the data as follows:
String a = t.Cols(2).Row(3); t.Col(2).Row(3) = "b";
But I'm losing the safty type with my current way of achieving this ... My problem is how to implement columns due to the different data types that the potential of the columns can get.
Does anyone have a clue?
source share