Compiling my code with -Xlint I found this:
warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.ArrayList<java.lang.String>
ArrayList<String> msgData = (ArrayList<String>)element;
This is the code:
ArrayList<ArrayList<String>> msg = new ArrayList<ArrayList<String>>();
//add some data to msg
Iterator i = msg.iterator();
while(i.hasNext()) {
Object element = i.next();
ArrayList<String> msgData = (ArrayList<String>)element;
}
how should the cast be done?
Your Iterator needs a type as well, like this:
On a side note, it’s better to program to interfaces, not to implementations. Thus, you’d write: