I want to make something like this. How I can do this pretty in java with generics?
public <T [Integer or String]> Float getFloat(<T> column) throws SQLException{
Float result;
try {
result = ResultSet.getFloat(column);
} catch (NullPointerException e) {
result = null;
}
return result;
}
Now my code looks like this:
public Float getFloat(String column) throws SQLException{
Float result;
try {
result = rs.getFloat(column);
} catch (NullPointerException e) {
result = null;
}
return result;
}
public Float getFloat(int column) throws SQLException{
Float result;
try {
result = rs.getFloat(column);
} catch (NullPointerException e) {
result = null;
}
return result;
}
I do this because method rs.getFloat() may receive String (Column label) & Integer (Column Index) only. But this not important for my method.