G
grz01
Hi,
I am trying to get some more grips on Java type-casting,
and have some questions... here the first one:
Compiling in Eclipse...
import java.util.ArrayList;
import java.util.List;
...
String s = "";
Object o = s;
List<String> sList = new ArrayList<String>();
List<Object> oList = (List<Object>)sList;
The first two assignments work fine, of course.
But the last assignment give me an error:
Cannot cast from List<String> to List<Object>
Can someone explain why?
And what is the correct formulation of the offending stmt?
/ grz01
I am trying to get some more grips on Java type-casting,
and have some questions... here the first one:
Compiling in Eclipse...
import java.util.ArrayList;
import java.util.List;
...
String s = "";
Object o = s;
List<String> sList = new ArrayList<String>();
List<Object> oList = (List<Object>)sList;
The first two assignments work fine, of course.
But the last assignment give me an error:
Cannot cast from List<String> to List<Object>
Can someone explain why?
And what is the correct formulation of the offending stmt?
/ grz01