With non-generic collections, a cast is required:
import java.util.ArrayList;
import java.util.List;
publicclass MainClass{
publicstaticvoid main(String[] argv){
List<String> gList = new ArrayList<String>();
List list = new ArrayList();
// more code
String s = gList.get(0); // no cast needed
s = (String)list.get(0); // cast required
}
}
8.22.generics
8.22.1.
When using generic collections, a cast is not needed to get (declared type) elements out of the collection.