I'm working on some set of abstractions representing an SQL result set and have written this methods:
public interface Column<T>{
//some methods
}
public class SqlRowExtractor{
public void doExtraction(){
Collection<Column<?>> cols = getColumns(); //Returns the collection of Column<T>.
//A particular result set may contain,
//for instance 2 Column<Date>,
//1 Column<Integer> and so fotrh
for(Column<?> c : cols){
put(c, get(c)); //1 <-------------------- HERE
//Compile-error
}
//other staff
}
public <T> void put(Column<T> c, T o){
//put the extracted value in another place
}
public <T> T get(Column<T> c) throws SQLException{
//extract the value of the row for the Column<T> c
}
}
I got compile-error at //1
, although it's perfectly clear by the signature of put
and get
methods that there is no way to put inaproppriate value. How can I fix the error in a type-safe way? The error message:
The method put(Column<T>, T) is not applicable for the arguments
(Column<capture#3-of ?>, capture#4-of ?)