Kotlin tus kwv tij yog dab tsi?
Kotlin tus kwv tij yog dab tsi?

Video: Kotlin tus kwv tij yog dab tsi?

Video: Kotlin tus kwv tij yog dab tsi?
Video: Txhaij Lauj - Tsim Txiaj Kwv Tij Thiaj Noog Moo (Cover) 2024, Hlis ntuj nqeg
Anonim

Kotlin muaj "chav kawm" rau cov chav kawm uas muaj ntau qhov piv txwv, thiab " khoom "rau singletons. Kuv ntseeg tias Scala ua qhov sib txawv? “ tus khub khoom "yog qhov txuas ntxiv ntawm lub tswvyim ntawm" khoom ”: ib khoom uas yog a tus khub mus rau ib chav kawm tshwj xeeb, thiab yog li muaj kev nkag mus rau nws cov txheej txheem thiab cov khoom ntiag tug.

Yog li ntawd, dab tsi yog tus khub khoom?

Ib khoom nrog tib lub npe raws li chav kawm hu ua a tus khub khoom . Hloov chaw, chav kawm yog tus khoom tus khub chav kawm. A tus khub chav kawm los yog khoom tuaj yeem nkag mus rau cov tswv cuab ntiag tug ntawm nws tus khub . Siv a tus khub khoom rau txoj kev thiab qhov tseem ceeb uas tsis yog tshwj xeeb rau cov piv txwv ntawm cov tus khub chav kawm.

Qhov thib ob, qhov sib txawv ntawm cov khoom thaiv thiab cov khoom sib koom ua ke hauv Kotlin yog dab tsi? A Tus khub khoom yog pib thaum cov chav kawm yog loaded (feem ntau yog thawj zaug nws tau hais los ntawm lwm yam code uas yog raug tua) whereas Yam khoom Cov lus tshaj tawm tau pib ua haujlwm tsis txaus ntseeg, thaum nkag mus rau thawj zaug.

Ib yam li ntawd, koj nkag mus rau qhov khoom khub hauv Kotlin li cas?

Cov khoom ua khub thiab lawv cov tswv cuab tsuas tuaj yeem nkag tau los ntawm cov chav kawm uas muaj npe, tsis yog los ntawm cov piv txwv ntawm cov chav kawm. Kotlin tsis txhawb nqa cov haujlwm hauv chav kawm uas tseem tuaj yeem hla dhau hauv subclasses (xws li @classmethod hauv Python).

Dab tsi yog qhov txawv ntawm cov khoom thiab chav kawm hauv Kotlin?

Kotlin qhia txog lub tswvyim ntawm ib khoom nyob saum qhov ntawd. Yog ib chav kawm piav qhia txog cov qauv uas tuaj yeem ua tau sai raws li thiab thaum xav tau thiab tso cai rau ntau zaus raws li xav tau, khoom es sawv cev rau ib qho piv txwv zoo li qub, thiab tsis tuaj yeem muaj ntau lossis tsawg dua qhov piv txwv no.

Pom zoo: