I'm clearing out the warnings in Eclipse for
ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
but I don't understand why Eclipse uses the wildcard <?>
periodically. Most of the time it puts in the correct type, i.e. ArrayList<Bicycle>
. But with the following code if I do the List
quickfix on Line 1
it changes to List<?>
while if I do the quickfix on ArrayList
first it changes to ArrayList<Object>
even though the at Line 2
the method calls Line 3
and returns List<String>
.
public List getList() {
List treq = new ArrayList();
List deptList = new ArrayList(); // Line 1
try {
treq = trDao.getList(status, dept, type, site);
deptList = trDao.getDepts(); // Line 2
}
catch (DAOException e) {
setError(FORM_RESULTS, e.getMessage());
}
request.setAttribute("form", this);
request.setAttribute("deptList", deptList);
return treq;
}
and
public List<String> getDepts() { // Line 3
Here is code which quickfixes trList as expected to ArrayList<RequestStudent> trList;
The main difference I see is the use of .add()
public ArrayList getListByRequestID(String request_id) throws DAOException {
ArrayList trList;
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
String SQL_GET_LIST = SELECT_QUERY + "WHERE trs.REQUEST_ID = ? " + "ORDER BY trs.STUDENT, trs.COURSE_ID";
try {
connection = ds.getConnection();
ps = connection.prepareStatement(SQL_GET_LIST);
ps.setString(1, request_id);
rs = ps.executeQuery();
trList = new ArrayList();
while (rs.next()) {
trList.add(mapResults(rs)); //mapResults returns a RequestStudent
}
}
return trList;
}