This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need help to resolve protected clone() error  RSS feed

 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the following code, I see this error:

CloneTest.java:66: clone() has protected access in java.lang.Object
cloned.address = (Address) address.clone();



 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a bit confusing. I believe you need to override the method in your Address class. You can leave it as protected and just return super.clone() if that's acceptable. Also, bring your salt shaker as I can't recollect ever using protected nor do I use Cloneable so it's entirely possible I'm spewing misinformation as it's not something I generally bother with on either count.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Address should implement Clonnable interface and should override the clone method to make this work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!