Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > cloning with generics

Reply
Thread Tools

cloning with generics

 
 
scott moss
Guest
Posts: n/a
 
      12-20-2004
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
 
Reply With Quote
 
 
 
 
Tilman Bohn
Guest
Posts: n/a
 
      12-20-2004
In message < >,
scott moss wrote on 20 Dec 2004 09:39:51 -0800:

[...]
> 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.


Which is why it was most recently answered last week.

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
generics depending on generics Soul VHDL 0 02-02-2009 09:14 AM
Can't convert a generics list of objects into a generics list ofinterfaces Juergen Berchtel Java 1 05-20-2005 02:07 PM
cloning =?Utf-8?B?QVZM?= ASP .Net 3 12-14-2004 12:01 PM
hard drive cloning tami Microsoft Certification 1 12-15-2003 06:12 PM
Cloning Possible? ASP .Net 1 11-11-2003 01:21 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57