File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton object creation using clone

 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to implement the Cloneable interface.

Also please provide the complete Stacktrace in your future posts.
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code which you are trying to execute?
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic