What is wrong with this clone()?

I have written this clone method for when the parent of the Employee class is abstract and the clone() method in the parent class is abstract.I wanted to copy the primitive data type of the Employee's object with this code instead of copying each primitive data type individually, but this code has problem with the line that I call clone() method. (This code is in Employee class) public Object clone() { Object obj = new Object(); Object object = obj.clone(); //Emphasis here return object; } the error is: The method clone() from the type Object is not visible. But my Employee class is in the class hierarchy which can access the protected clone() method in the Object class. This is my simple Employee class: public class Employee extends Person implements Cloneable { private int ID; public Employee() { ID = 0; } public void setID(int ID) { this.ID = ID; } public int getID() { return ID; } public Object clone1() throws CloneNotSupportedException { try { Object obj = new Object(); Object object = obj.clone(); return object; } catch (CloneNotSupportedException ex) { return null; } }
+1. Because as I understand it know the situation is actually a bit tricky, not just a simple clone() case.

以上就是What is wrong with this clone()?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准