I'm trying to implement Spring's RowMapper interface, however, my IDE is prompting me to cast the return object to "T" and I don't understand why. Can anyone explain what I'm missing?
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?
}
}
TrepresentsUser? Perhaps you mean to implement the interface asimplements RowMapper<User>instead?UserMapper<T>, you're saying that any type can be specified for a new instance of it. For example,new UserMapper<String>(). Yet the class will only ever return aUser!