wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics and cloning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics and cloning" Watch "Generics and cloning" New topic
Author

Generics and cloning

Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
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

Joined: Jan 17, 2005
Posts: 117
hi how do I remove the smily from my post above ?
[ May 22, 2005: Message edited by: Sreedevi Vinod ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

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 ]

Tony Morris
Java Q&A (FAQ, Trivia)
 
 
subject: Generics and cloning
 
Similar Threads
Class objects into ArrayList
Why is Java cAse sEnSiTIvE?
Basic Bean question
Question reg. Adding elements to HashSet / TreeSet
Set of Set with generics