第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于eclipse中使用clone()方法的問題

關于eclipse中使用clone()方法的問題

慕碼人3756810 2018-03-28 23:30:57
問題描述:eclipse的版本是oxygen的,JDK和jre的版本是10;在eclipse中使用clone()方法進行淺克隆的時候,出現(xiàn)如下提示的編譯錯誤。提示“返回類型與Object.clone()不兼容”,具體位置如下圖所示:但是我在使用JDK編譯運行的時候是正常的,所以基本上能確定是eclipse哪里出現(xiàn)問題,所以想請問各位大佬這個是什么原因造成的問題(我猜測是eclipse的版本和JDK的版本不兼容的問題,但是不敢確定)源碼附上:public?class?Address?{ ????????private?String?country; ????????private?String?province; ????????private?String?city; ???????? ????????public?void?setCountry(String?country)?{ ????????????this.country=country; ????????} ???????? ????????public?void?setProvince(String?province)?{ ????????????this.province=province; ????????} ???????? ????????public?void?setCity(String?city)?{ ????????????this.city=city; ????????} ???????? ????????public?String?toString()?{ ????????????//return?"地址:"+"國家:"+country+","+"省:"+province+","+"市:"+city; ???????????? ????????????StringBuilder?sb=new?StringBuilder(); ????????????sb.append("國家:"+country+","); ????????????sb.append("省:"+province+","); ????????????sb.append("市:"+city); ????????????return?sb.toString(); ????????} ???? }public?class?Employee?implements?Cloneable{??? ????????private?String?name; ????????private?int?age; ????????private?Address?address; ???? ????????public?void?setName(String?name){ ????????????this.name=name; ????????} ???? ????????public?void?setAge(int?age){ ????????????this.age=age; ????????} ???? ????????public?void?setAddress(Address?address)?{ ????????????this.address=address; ????????} ???????? ?????????public?Address?getAddress(){ ???????????????return?this.address; ????????} ???? ????????public?Employee?clone()?{ ????????????Employee?employee=null; ????????????try?{ ????????????????employee=(Employee)super.clone(); ????????????}catch(CloneNotSupportedException?e)?{ ????????????????e.printStackTrace(); ????????????} ???????? ????????????return?employee; ????????} ???? ???? ????????public?String?toString()?{?????????????????????//重寫toString方法,使用字符串輸出對象 ????????????StringBuilder?sb=new?StringBuilder(); ????????????sb.append("姓名:"+name+","); ????????????sb.append("年齡:"+age+'\n'); ????????????sb.append(address); ????????????return?sb.toString(); ????????} }public?class?Test?{ ????public?static?void?main(String[]?args)?{ ????????System.out.println("克隆之前:"); ????????Address?address=new?Address(); ????????address.setCountry("中國"); ????????address.setProvince("四川"); ????????address.setCity("成都"); ????????Employee?employee1=new?Employee(); ????????employee1.setName("張XX"); ????????employee1.setAge(30); ????????employee1.setAddress(address); ????????System.out.println("員工1的信息"); ????????System.out.println(employee1); ???????? ????????System.out.println("克隆之后:"); ????????Employee?employee2=employee1.clone();??//使用淺克隆 ???????????????????????? ????????employee2.setName("陳XX");???????????? ????????employee2.setAge(20); ????????employee2.getAddress().setCountry("中國");???????????? ????????employee2.getAddress().setProvince("山東"); ????????employee2.getAddress().setCity("濟南"); ???????? ???????? ????????System.out.println("員工1的信息"); ????????System.out.println(employee1); ????????System.out.println("員工2的信息"); ????????System.out.println(employee2); ????} }
查看完整描述

1 回答

?
臥龍絕圣

TA貢獻65條經(jīng)驗 獲得超25個贊

你這是clone方法么?類型都不是Object

查看完整回答
反對 回復 2018-03-29
  • 1 回答
  • 0 關注
  • 1190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號