Puas yog equalsIgnoreCase null nyab xeeb?
Puas yog equalsIgnoreCase null nyab xeeb?

Video: Puas yog equalsIgnoreCase null nyab xeeb?

Video: Puas yog equalsIgnoreCase null nyab xeeb?
Video: "Puag Yoj Mas" [OFFICIAL MUSIC VIDEO] - KT Killing Em 2024, Kaum ib hlis
Anonim

equalsIgnoreCase ( null ); yuav twv yuav raug hu ua NullPointerException. Yog li txoj kev sib npaug tsis yog tsim los ntsuas seb qhov khoom puas yog null , tsuas yog vim koj tsis tuaj yeem hu rau lawv null . Tsis muaj teeb meem ua li no, ntxiv rau nws yog txoj hauv kev nyab xeeb dua kuaj thaum tsis muaj peev xwm null taw tes kev zam.

Qhov sib thooj, yog StringUtils sib npaug tsis muaj kev nyab xeeb?

Kev sib piv () txoj hauv kev StringUtils class yog a null - nyab xeeb version ntawm txoj kev sib pivTo() txoj hlua ntawm chav kawm thiab tes null qhov tseem ceeb los ntawm kev xav txog a null tus nqi tsawg dua qhov tsis- null tus nqi. Ob null xam qhov tseem ceeb sib npaug.

Qhov thib ob, txoj hlua puas tuaj yeem yog null? Ib qho khoob txoj hlua yog a txoj hlua piv txwv ntawm xoom ntev, whereas a null txoj hlua tsis muaj nqi kiag li. Ib qho khoob txoj hlua yog sawv cev li "". Nws yog ib tug cim ib theem zuj zus ntawm xoom cim. A null txoj hlua yog sawv cev los ntawm null.

Ntxiv mus, yog Java sib npaug null nyab xeeb?

sib npaug (str1, nr 2); Nws yog null nyab xeeb . Nws tsis tshua muaj siv txoj hlua kim dua. sib npaug () txoj kev vim hais tias cov hlua zoo tib yam ntawm Android yuav luag ib txwm sib piv qhov tseeb nrog "=" operand ua tsaug rau Android's String Pooling, thiab kev kuaj xyuas ntev yog txoj hauv kev nrawm los lim tawm feem ntau tsis sib haum.

Peb puas tuaj yeem piv Null nrog null hauv Java?

Hauv java ua tsuas yog siv xwb ua tau muaj tus nqi null . Yog hais tias ob qho tib si siv null ces ob leeg muaj nqi ib yam. Li no null == null ua tseeb. Lwm yog vim li cas null == null rov qab muaj tseeb yog tias tsis muaj tus neeg teb xov tooj rau kev tshuaj xyuas seb puas yog siv null ; tsis muaj "yog" tus neeg teb xov tooj (piv txwv li yog (myRef yog null ) {}).

Pom zoo: