Exception in thread "main" java.lang.CloneNotSupportedException: Test2
at java.lang.Object.clone(Native Method)
at Test2.clone(Test2.java:4)
at Test.main(Test.java:5)
という風にオブジェクトのクローンを作るとCloneNotSupportedExceptionが出てしまいます
Testがメインクラス、Test1がクローンを作りたいオブジェクトのクラス、Test2がクローンを作るクラスです
java
1public class Test2 { 2 public Test1 clone(Test1 t) throws CloneNotSupportedException{ 3 return(Test1)super.clone(); 4 } 5 6} 7 8public class Test implements Cloneable{ 9 public static void main(String[] args) throws CloneNotSupportedException { 10 Test1 t = new Test1(1); 11 Test2 test2= new Test2(); 12 Test1 t1 = test2.clone(t); 13 t1.move(); 14 System.out.println(t.locate); 15 } 16}
原因と解決策を教えてください
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。