Java??????У?java.lang.Object
???????????? ???????[ 2014/5/29 13:22:02 ] ????????Java java.lang.Object
??????????????main()?????У?new???Oject??????????????????clone?????????????????????????????"The method clone() from the type Object is not visible"
????why? ?????????????????ObjectTest???ж????Oject?????????????clone()?????????Object????clone()????????壬??????????????protected?????????????????????protected???ε????????????????????????????????????????????????Object????ObjectTest??????????У?????ObjectTest?????Object????Object??????????????????????????????Object???ò??????protected??????????????"??????е???????????"?????????
????"??????е???????????"??????????????????????е??????????????????????????????????????????????????????????protected???ε?????????/???????? ????????????????????????????????????protected???ε?????????super????????
?????????????????????????????????????????????
1 package com.corn.objectsummary;
2
3
4 public class ObjectTest {
5
6 public static void main(String[] args) {
7 ObjectTest ot1 = new ObjectTest();
8
9 try {
10 ObjectTest ot2 = (ObjectTest) ot1.clone();
11 } catch (CloneNotSupportedException e) {
12 // TODO Auto-generated catch block
13 e.printStackTrace();
14 }
15 }
16
17 }
|
?????????????????????????????????????
?????????????????й????л????"java.lang.CloneNotSupportedException"??????clone()??????δ??????????????????????Java?е????漲??
????clone()?????????????????Cloneable?????????????Cloneable??????????????????Object???clone()????????????CloneNotSupportedException????
????Cloneable????????????????????????????κη???????????Object.clone()??????????????????????á?
??????????????????????????????????????clone()?????????????
1 package com.corn.objectsummary;
2
3 public class ObjectTest implements Cloneable {
4
5 public static void main(String[] args) {
6
7 ObjectTest ot1 = new ObjectTest();
8
9 try {
10 ObjectTest ot2 = (ObjectTest) ot1.clone();
11 System.out.println("ot2:" + ot2);
12 } catch (CloneNotSupportedException e) {
13 // TODO Auto-generated catch block
14 e.printStackTrace();
15 }
16 }
17
18 }
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11