S
scott moss
I need to clone a generic ArrayList. But clone(), of coure, returns
an object and has not, as far as I can tell been "generified".
Consequently, I need to cast in the old way -- albeit to a generic
ArrayList. The relevant bits of code are:
{ArrayList<ArrayList<BindingVariable>> bindings;
[snip]
for (ArrayList<BindingVariable> bindingList : newBindings) {
ArrayList<BindingVariable> currList =
(ArrayList<BindingVariable>) bindings.get(bIndex).clone();
......
This gives me the compiler warning about an unchecked cast. Without
the cast I get an incompatible types error since the uncast clone need
not be an ArrayList<BindingVariable> The code runs but I would prefer
a compile time error to a runtime error when messing about with the
code at some later time.
This isn't a high priority, but I suspect that there are a lot of us
coming to terms with generics and a solution might be of some general
interest. Certainly, I'd welcome advice on this.
Thanks
Scott
an object and has not, as far as I can tell been "generified".
Consequently, I need to cast in the old way -- albeit to a generic
ArrayList. The relevant bits of code are:
{ArrayList<ArrayList<BindingVariable>> bindings;
[snip]
for (ArrayList<BindingVariable> bindingList : newBindings) {
ArrayList<BindingVariable> currList =
(ArrayList<BindingVariable>) bindings.get(bIndex).clone();
......
This gives me the compiler warning about an unchecked cast. Without
the cast I get an incompatible types error since the uncast clone need
not be an ArrayList<BindingVariable> The code runs but I would prefer
a compile time error to a runtime error when messing about with the
code at some later time.
This isn't a high priority, but I suspect that there are a lot of us
coming to terms with generics and a solution might be of some general
interest. Certainly, I'd welcome advice on this.
Thanks
Scott