Yam twg ntawm hom khoom no tuaj yeem clone ib qho khoom?
Yam twg ntawm hom khoom no tuaj yeem clone ib qho khoom?

Video: Yam twg ntawm hom khoom no tuaj yeem clone ib qho khoom?

Video: Yam twg ntawm hom khoom no tuaj yeem clone ib qho khoom?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim

Cov Chav Kawm Object 's clone () txoj kev tsim thiab xa rov qab a luam ntawm khoom , nrog tib yam chav kawm thiab nrog rau tag nrho cov teb muaj qhov zoo ib yam. Txawm li cas los xij, Yam khoom . clone () cuam tshuam ib qho CloneNotSupportedException tshwj tsis yog qhov khoom yog ib qho piv txwv ntawm a chav kawm uas siv cov cim interface Cloneable.

Tom qab ntawd, ua li cas koj clone ib yam khoom?

Tsim ib daim qauv siv clone () method Cov chav kawm uas nws cov khoom daim ntawv yuav tsum tau muaj rau pej xeem clone txoj kev nyob rau hauv nws los yog nyob rau hauv ib tug ntawm nws cov niam txiv chav kawm ntawv. Txhua chav kawm uas siv clone () yuav tsum hu super. clone () kom tau txais lub cloned khoom siv. Cov chav kawm kuj yuav tsum siv java.

Cov txheej txheem hauv chav kawm yog dab tsi? Cov txheej txheem ntawm Object class piv cov muab khoom rau qhov no khoom . tsim thiab xa rov qab daim ntawv luam (clone) ntawm qhov no khoom . rov qab txoj hlua sawv cev ntawm qhov no khoom . sawv ib leeg, tos qhov no cov khoom saib xyuas.

Ib yam li ntawd, vim li cas clone txoj kev txhais hauv cov chav kawm khoom?

clone () txoj kev muaj defaulting ntawm daim ntawv ntiav (tsim daim ntawv the khoom , luam cov ntaub ntawv). Raws li kev sib tshuam tsis muaj kev siv (qhov no tau hloov pauv los ntawm Java 8 txuas ntxiv), nws tau muab tso rau hauv Object class (hauv paus) thiab ua Cloneable ua tus cim interface (tsis muaj txoj kev ).

Cov chav kawm twg muaj cov txheej txheem clone?

Cov clone () txoj kev ntawm Object class yog siv rau clone ib khoom . The java. lang. Cloneable interface yuav tsum tau siv los ntawm cov chav kawm nws khoom clone peb xav tsim.

Pom zoo: