Sib piv yuav tsum yog siv thaum koj piv cov piv txwv ntawm tib chav kawmTus sib piv tuaj yeem siv los sib piv cov piv txwv ntawm cov chav sib txawv. Sib piv yog siv los ntawm cov chav kawm uas yuav tsum tau txhais lub ntuj xaj rau nws cov khoom. Piv txwv li, String siv Comparable.
Vim li cas thiaj sib piv thiab sib piv sib piv yog xav tau?
Sib piv thiab Sib piv ob qho tib si yog interfaces thiab tuaj yeem siv los txheeb xyuas cov khoom sau… Hauv lwm lo lus, peb tuaj yeem txheeb xyuas qhov sau los ntawm ib lub ntsiab lus xws li id, npe, thiab nqe. Tus Comparator muab ntau yam kev sib cais.
Dab tsi yog ob qhov txiaj ntsig tseem ceeb ntawm Kev Sib Tw dhau qhov sib piv?
Los ntawm kev siv cov sib piv, khoom tuaj yeem txheeb raws ntau dua ib qho ntawm cov chav kawm. Whereas Comparable tso cai rau koj txheeb cov khoom hauv cov khoom sau raws li ib qho chaw xwb.
Peb puas tuaj yeem siv Comparator yam tsis muaj kev sib piv?
3 Teb. Y Koj tsis siv Comparable. Koj siv Comparator. Sib piv yog ib qho interface siv los ntawm cov khoom los qhia lawv cov kev txiav txim nrog lwm yam khoom ntawm tib hom.
Qhov twg yog siv tus piv?
Ib lub voj voog sib piv piv ob qhov hluav taws xob thiab cov khoom tawm yog 1 (qhov hluav taws xob ntawm sab ntxiv) lossis 0 (qhov hluav taws xob ntawm qhov tsis zoo) los qhia qhov twg loj dua. Cov kev sib piv feem ntau siv, piv txwv li, txhawm rau txheeb xyuas seb qhov kev tawm tswv yim puas tau mus txog qee qhov kev txiav txim siab