小白求助!
普世干 2014-07-30 05:50:12 代码如下:
class Address
{
String detail ;
public Address(String detail){
this.detail = detail ;
}
}
class User implements Cloneable
{
int age ;
Address address ;
public User(int age){
this.age =age ;
address = new Address("山东莱芜");
}
public User clone()
throws CloneNotsupportedException
{
return (User)super.clone() ;
}
}
public class CloneTest
{
public static void main(String[] args)
throws CloneNotSupportedException{
User u1 = new User(23) ;
User u2 = u1.clone();
System.out.println(u1 == u2) ;
System.out.println(u1.address == u2.address) ;
}
}
在eclipse中出现错误一直不知道如何修改?
运行如下:Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method clone() from the type User refers to the missing type CloneNotsupportedException
at CloneTest.main(CloneTest.java:27)