1
我正在研究SpringJdbc代碼,注意到的是,當彈簧想要提取輸出參數的結果,它直接使用類型不安全方法getObject(int index)
:提取輸出參數VS結果Spring的JdbcTemplate設置
Object out = cs.getObject(sqlColIndex);
,他們wrote more code嘗試找出確切類型:
public static Object getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException {
if (requiredType == null) {
return getResultSetValue(rs, index);
}
Object value;
// Explicitly extract typed value, as far as possible.
if (String.class == requiredType) {
return rs.getString(index);
}
else if (boolean.class == requiredType || Boolean.class == requiredType) {
value = rs.getBoolean(index);
}
else if (byte.class == requiredType || Byte.class == requiredType) {
......
.....
這背後的原因是什麼?