File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Singleton object creation using clone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Singleton object creation using clone" Watch "Singleton object creation using clone" New topic
Author

Singleton object creation using clone

ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

hi all ,

I have my singleton class


and i also have another class where we are creating the singeton object :-


Now i want my to create an instance of singleton using the clone at line 1 but i get the exception java.lang.Error -->Unresolved compilation problem . Now my question is if SingletonObject is an instance of the Object class i should be able to call the clone() method on it . I cant understand why we cant call clone o0n singleton object
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

You need to implement the Cloneable interface.

Also please provide the complete Stacktrace in your future posts.


Mohamed Sanaulla | My Blog
ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

the stack trace is :-
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method clone() from the type Object is not visible

at com.example.Singleton.Clone.main(Clone.java:9)

even on implementing the clone method in the Singletonobject the error is the same as above
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Can you post the code which you are trying to execute?
ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

I got the answer :-
My SingletonObject class is implementing the Cloneable interface and inside the clone method of my class
i need to call super.clone() . this helps me in creating the singletonobject instance using the clone method
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton object creation using clone