Puas yog Java Util sib piv tus ua haujlwm interface?
Puas yog Java Util sib piv tus ua haujlwm interface?

Video: Puas yog Java Util sib piv tus ua haujlwm interface?

Video: Puas yog Java Util sib piv tus ua haujlwm interface?
Video: Сравнение G-Shock Magma Ocean Коллекция | GPRB1000 Rangeman | GWF1035 Frogman | MT... 2024, Kaum ib hlis
Anonim

Taw qhia. Cov sib piv interface tau dhau los ua kev kho dua tshiab hauv Java8 thaum tseem khaws nws cov ntsiab lus uas yog los sib piv thiab txheeb cov khoom hauv cov khoom sau. Muab piv tam sim no txhawb kev tshaj tawm ntawm lambda kab lus raws li nws yog ib Functional Interface . Ntawm no yog ib qho yooj yim qhov chaws rau lub java ua.

Hais txog qhov no, piv txwv yog kev ua haujlwm interface?

Tag nrho cov khoom hauv Java twb muaj qhov kev siv ntawm equals() txoj kev, vim lawv tau txais nws los ntawm chav kawm Object. Yog li ntawd, Muab piv yog a ua haujlwm interface vim tias tsuas muaj ib txoj kev ua tsis tau tiav: piv (T o1, T o2).

Ib tug kuj yuav nug, dab tsi ua piv txwv ua Java? Java Comparator yog ib qho interface rau sorting Java khoom. Invoked los ntawm " java ua . tus piv ,” Java Comparator piv ob Java cov khoom nyob rau hauv ib tug "sib piv (Object 01, Object 02)" hom. Siv cov txheej txheem configurable, Java Comparator tuaj yeem sib piv cov khoom kom rov qab tau tus lej raws li qhov zoo, sib npaug lossis tsis zoo sib piv.

Tsis tas li ntawd, dab tsi yog qhov kev siv ntawm kev ua haujlwm hauv Java?

A ua haujlwm interface yog ib interface uas tsuas muaj ib txoj kev paub daws teeb meem xwb. Lawv tuaj yeem muaj ib qho kev ua haujlwm nkaus xwb los nthuav tawm. Los ntawm Java 8 txuas ntxiv mus, lambda kab lus tuaj yeem siv los sawv cev rau qhov piv txwv ntawm a ua haujlwm interface . Runnable, ActionListener, Sib piv yog qee qhov piv txwv ntawm ua haujlwm interfaces.

Puas yog Lambda tsuas yog rau kev ua haujlwm cuam tshuam?

Yog lawm, lambda siv tau cov lus qhia nkaus xwb los siv txoj kev paub daws teeb meem hauv a ua haujlwm interface . Java yog hom lus hom lus, hos lambda lus yog a ua haujlwm feature. Txhawm rau ntxiv lambda qhia kev txhawb nqa rau Java, Java 8 txiav txim siab los qhia ua haujlwm interfaces.

Pom zoo: