Ronnie Phelps wrote:List<Object> objectList = new ArrayList();
List<String> stringList = new ArrayList();
You actually should *not* be doing this -- assigning a non generics collection to a generics one. This is allowed in
Java in order to maintain backward compatibility with Java 1.4 and eariler.
Ronnie Phelps wrote:objectList = stringList; // This doesn't work
It doesn't work because it is not a valid assignment. A list of strings can only hold string objects. If you are allowed to assign it to a reference of a list of objects, then you will be able to add any object type list, that another reference believes it to only hold strings.
Ronnie Phelps wrote:
objectList = (List<Object>)stringList; //this doesn't work either
Same reason as previous. Regardless, if you really want to break generics (by casting), then you can do it by casting it to a List that doesn't use generics first.
Henry