我按照java核心编程中的代码输入 public Employee clone() throws CloneNotSupportedException{
Employee cloned=(Employee)super.clone();
cloned.hireday=(Date) hireday.clone();
return cloned;
}为什么会有The return type is incompatible with Object.clone()的错误呢

解决方案 »

  1.   

    方法写错了吧。返回值是object,而其你要实现Cloneable接口
    @Override
    protected Object clone() throws CloneNotSupportedException {
    // TODO Auto-generated method stub
    return super.clone();
    }
      

  2.   


    public Object clone() throws CloneNotSupportedException{
            Employee cloned=(Employee)super.clone();
            cloned.hireday=(Date) hireday.clone();
            return cloned;
        }
      

  3.   

    没有实现Cloneable接口 是有异常的。
      

  4.   

    cloneable接口问题,你没有实现这个接口