Re: correct usage for @SuppressWarnings("unchecked")
On Mon, 19 Apr 2010 13:34:24 -0500, Chris Riesbeck wrote:
Thufir wrote:
@SuppressWarnings("unchecked")
private List<Beatle> populateBeatles() {
...
ArrayList<ArrayList<String>> table = database.getTable();
Is getTable() defined to return ArrayList<ArrayList<String>>?
for some reason it was, rather than:
List<List<String>>
I was working from:
public ArrayList<ArrayList<Object>> Results2Array(ResultSet rs)
throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
ArrayList<ArrayList<Object>> al = new ArrayList<ArrayList<Object>>
();
while (rs.next()) {
ArrayList<Object> record = new ArrayList<Object>();
for (int i = 1; i <= columns; i++) {
Object value = rs.getObject(i);
record.add(value);
}
al.add(record);
}
return al;
}
http://stackoverflow.com/questions/1685038/convert-java-resultset-to-
string-array
(don't ask me why this person capitalizes the method name, pls.)
and, while I don't have my code at the moment, I wasn't able to get it to
return what I wanted, which was a List of List of String. So, I went to
a List of Foo (in my case, Beatle). However, that didn't seem
particularly "generic", as it only applies to Foo's (or Beatles). Hence,
the question.
Even a List<List<String>> is returned, there's going to have to be an
unchecked cast, it seems -- unless each String is sent to a Foo
constructor or factory of some variety. Perhaps that would be more
extensible?
I suppose Foo could extend List<String>, but that seems to lock down the
design of Foo a bit.
-Thufir