Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics and cloning

 
Sreedevi Vinod
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

When I try to compile the following code, I get warnings about the unchecked cast used for the return type of the clone method. How do
I rectify this ?


Thanks
Devi

[ May 22, 2005: Message edited by: Sreedevi Vinod ]
[ May 22, 2005: Message edited by: Barry Gaunt ]
 
Sreedevi Vinod
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi how do I remove the smily from my post above ?
[ May 22, 2005: Message edited by: Sreedevi Vinod ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Smiley?

There's a disable smiley check box at the bottom of the form in which you enter your code. You may have to scroll down a bit though. Or you can add space between the offending characters.

Oh now I see it's because of the > and ) being close together.
I'll fix it.
[ May 22, 2005: Message edited by: Barry Gaunt ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The Cloneable interface is arguably the most broken (I can think of only one other candidate) part of the core J2SE API. It always has been. Since the introduction of JSR14, it is even more (but only slightly in comparison) broken. You can either:
a) put up with it and therefore, put up with its extreme shortcomings.
b) do it properly (it doesn't offer you much anyway).

Cloning an object itself (regardless of the broken API) requires an obscure case justification because it is almost certainly unnecessary. If you insist on cloning an object (for a justified reasoning or not), you can simply do something like (disclaimer: off the top of my head with no real thought):


(Edit: disabled smilies)
[ May 22, 2005: Message edited by: Tony Morris ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic