473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How would you clone this class?!

Expand|Select|Wrap|Line Numbers
  1. class Asdf<T extends Cloneable> implements Cloneable {
  2.    public T t;
  3.    protected Object clone() throws CloneNotSupportedException {
  4.       ...
  5.       t.clone(); // The method is not visible
  6.       ...
  7.    }
  8. }
Thanks,
Etam.
Oct 11 '08 #1
1 1235
JosAH
11,448 Expert 8TB
You can't clone that object of generic class T. The Cloneable interface does not
guarantee that you can clone an object that implements that interface (also read
the API documentation for that interface).

You can either try to use reflection and find the clone() method (very ugly) or
create your own interface:

Expand|Select|Wrap|Line Numbers
  1. public interface MyCloneable extends Cloneable {
  2.    public Object clone();
  3. }
  4.  
Make your class T implement this interface.

kind regards,

Jos
Oct 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some...
4
by: Vincent | last post by:
Hey, I have a problem to understand the underlaying of clone method. Hope someone can help me out. Let's say, clonedObject = originalObject.clone() (syntax may be wrong, but you know what I...
13
by: Tony Johansson | last post by:
Hello Experts! I want to create a virtual clone but I'm not sure if this is the wright way. Can somebody tell me where I have made error in the code. I get some compile error in this code also....
6
by: Amil Hanish | last post by:
I have two classes that I have implemented ICloneable. From my top-level class, how to I clone the base class values: See "how do I clone the base class values" below. Since Clone returns an...
4
by: Brian Keating | last post by:
Hi there, Consider this from MSDN *Notes to Inheritors When you derive from DataGridViewCheckBoxCell and add new properties to the derived class, be sure to override the Clone method to copy the...
8
by: Noozer | last post by:
I'm looking for a way to generate a "clone" of an object. Right now I need to write a Clone function for every class that make and I'd like to have a generic routine. Instead of doing this: For...
2
by: Steven | last post by:
Hi, I have created my own node (class MyNode : TreeNode) for a TreeView. To populate the treeview, i use something like MyNode newNode = new MyNode("Bla bla bla","0","1") for example. But, to...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.