Dab tsi yog chav kawm implicit hauv Scala?
Dab tsi yog chav kawm implicit hauv Scala?

Video: Dab tsi yog chav kawm implicit hauv Scala?

Video: Dab tsi yog chav kawm implicit hauv Scala?
Video: Finance with Python! Portfolio Diversification and Risk 2024, Kaum ib hlis
Anonim

Scala 2.10 tau qhia txog qhov tshiab hu ua cov chav kawm implicit . Ib chav kawm implicit yog a chav kawm cim nrog cov cuam tshuam lo lus tseem ceeb. Lo lus tseem ceeb no ua rau chav kawm thawj constructor muaj rau cuam tshuam kev hloov pauv thaum lub chav kawm yog nyob rau hauv qhov. Implicit chav kawm tau thov hauv SIP-13.

Tsis tas li ntawd, dab tsi yog implicit hauv Scala?

Cov cuam tshuam lo lus tseem ceeb qhia tias cov khoom siv tau siv tau implicitly . Scala yuav xub nrhiav cuam tshuam txhais thiab cuam tshuam parameters uas tuaj yeem nkag tau ncaj qha (tsis muaj prefix) ntawm qhov taw tes tus qauv nrog cov cuam tshuam parameter block hu ua.

Ib yam li ntawd, hom Scala yog dab tsi? Hauv cov ntsiab lus ntawm Scala , a hom chav kawm yog ib tsev neeg ntawm hom uas txhawb kev paub txog kev coj cwj pwm. Qhov no yuav yog, piv txwv li, tsev neeg ntawm hom uas nthuav tawm ib tus cim integer cim. Qhov no yog siv los ntawm ib tug zoo thiab ib tug xov tooj ntawm implicit piv txwv ntawm qhov zoo.

Tom qab ntawd, ib tug kuj yuav nug, Scala implicit ua haujlwm li cas?

Scala "implicits" tso cai rau koj tshem tawm txoj hauv kev hu lossis xa cov hloov pauv ncaj qha tab sis hloov pauv kev cia siab rau lub compiler los ua kev sib txuas rau koj. Kev cuam tshuam functions yog def s uas yuav raug hu ua cia li yog tias cov cai yuav tsis txwv tsis pub compile.

Dab tsi yog Implicits?

cuam tshuam . Siv lub adjective cuam tshuam thaum koj txhais hais tias ib yam dab tsi yog to taub tab sis tsis meej meej. Tab sis lub adjective cuam tshuam kuj txhais tau tias "ua tiav yam tsis muaj kev poob siab," yog li peb tuaj yeem hais tias peb muaj cuam tshuam kev ntseeg lossis kev ntseeg ntawm ib tug neeg.

Pom zoo: