i' ve a code snippet like below. but it gives error at list.add(mapp开发者_如何学编程er.mapRow()); line says "The method add(K) in the type List is not applicable for the arguments (Object)". how can i fix it?
thanks.
public List<K> fetchData(JStarRowMapper mapper) {
List<K> list = new ArrayList<K>();
list.add(mapper.mapRow());
return list;
}
public class IncomingRowMapper<K> implements JStarRowMapper {
@Override
public IncomingVO mapRow(ResultSet rs) throws SQLException {
IncomingVO vo = new IncomingVO();
vo.setId(rs.getInt("id"));
vo.setUsername(rs.getString("username"));
vo.setProcessDate(rs.getTimestamp("process_date"));
vo.setProcessCount(rs.getInt("process_count"));
return vo;
}
}
public interface JStarRowMapper<K> {
abstract public K mapRow(ResultSet rs) throws SQLException;
}
In the first snippet you should declare mapper as
JStarRowMapper<K>
Also mapRow is called without parameters, whereas it needs a ResultSet parameter
Another problem is that IncomingRowMapper
should be declared as:
public class IncomingRowMapper implements JStarRowMapper<IncomingVO> { ...
精彩评论