我正在尝试实现Spring的RowMapper接口,但是我的IDE提示我将返回对象强制转换为"T",我不明白为什么。有人可以解释一下我错过了什么吗?
public class UserMapper<T> implements RowMapper<T> {
public T mapRow(ResultSet rs, int row) throws SQLException {
User user = new User();
user.firstName(rs.getInt("fname"));
user.lastName(rs.getFloat("lname"));
return user; // Why am I being prompted to cast this to "T", should this be fine?
}
}
T
是代表User
?也许你的意思是应该实现接口,改为使用implements RowMapper<User>
吗? - Kirk Woll