ArrayList of ArrayList and unchecked conversions
I seem to be having some trouble with a list of lists. Here's the
code:
//build a list of lists
ArrayList<ArrayList> listOfLists = new ArrayList<ArrayList>();
//build a list of DataPoints
ArrayList<DataPoint> listOfPoints = new ArrayList<DataPoint>();
//put a few DataPoints in the listOfPoints
DataPoint point = new DataPoint("Howdy", 1);
listOfPoints.add(point);
point = new DataPoint("Dude", 2);
listOfPoints.add(point);
//put the listOfPoints in the listOfLists
listOfLists.add(listOfPoints);
//build a second list of DataPoinsts and put that in the listOfLIsts
listOfPoints = new ArrayList<DataPoint>();
point = new DataPoint("How are you", 20);
listOfPoints.add(point);
listOfLists.add(listOfPoints);
//get the first element from each listOfPoints stored in the
listOfLists
System.out.println(listOfLists.get(0).get(0)); // both work fine
System.out.println(listOfLists.get(1).get(0));
//try to retrieve the first list of data from the listOfLists
listOfPoints = listOfLists.get(0); // ??? causes an unchecked
conversion
System.out.println(listOfPoints.get(0)); //works fine
//try to get the DataPoint directly from the listOfLists
DataPoint retrievedPoint =
listOfLists.get(0).get(0); // ??? causes "incompatible
type"
//----DataPoint Class Definition in seperate file
public class DataPoint
{
public Object data;
public int time;
public DataPoint ()
{
data = null;
time = 0;
}
public DataPoint(Object data, int ticks)
{
this.data = data;
this.time = ticks;
}
public String toString()
{
String s = new String(data.toString() + " " + time);
return s;
}
}
The questions are these:
1) Why does the first ??? line cause the unchecked conversion?
1a) If that code isn't the right way to retrieve one of the lists
stored in the listOfLists, what is?
2) Why do both System.out.println statements work fine but the
second ??? causes an "incompatible type"
2a) How do I go about retrieving data items from one of the sublists
properly?
Any help greatly appreciated!