Qhov kev sib cav wildcard puas tuaj yeem raug khi?
Qhov kev sib cav wildcard puas tuaj yeem raug khi?

Video: Qhov kev sib cav wildcard puas tuaj yeem raug khi?

Video: Qhov kev sib cav wildcard puas tuaj yeem raug khi?
Video: Qhia Qhov Nyiaj Tub Wb Sib Cav 2024, Kaum ib hlis
Anonim

A wildcard tau muaj ib leeg xwb khi , thaum ib hom parameter tau muaj ob peb txoj cai. A wildcard tau muaj qhov qis los yog sab sauv khi , thaum tsis muaj qhov qis dua khi rau ib hom parameter.

Ib yam li ntawd ib tug yuav nug, dab tsi yog bounded thiab unbounded wildcards nyob rau hauv generics?

bounded thiab unbounded wildcards nyob rau hauv generics yog siv los khi txhua yam. Ntawm qhov tod tes, bounded wildcards muab kev yooj yooj yim nyob rau hauv khi. Txhua yam nrog bounded wildcards tuaj yeem tsuas yog instantiated nyob rau hauv khi thiab ib qho instantiation sab nraum bound yuav ua rau compiler yuam kev.

Secondly, uas yog lub cim wildcard siv rau generic hom specification?) yog lub npe hu ua daim ntawv qub hauv muaj programming. Nws sawv cev rau qhov tsis paub hom . Cov daim ntawv qub tuaj yeem yog siv nyob rau hauv ntau yam xwm txheej xws li cov hom ntawm ib qho parameter, teb, lossis qhov sib txawv hauv zos; qee zaum raws li kev rov qab los hom.

Ib yam li ntawd, tib neeg nug, dab tsi yog syntax rau bounded type parameters?

Tshaj tawm a bounded yam parameter , lis yam parameter lub npe, ua raws li lo lus tseem ceeb txuas ntxiv, ua raws nws sab saud khi , uas hauv qhov piv txwv no yog Number. Nco ntsoov tias, hauv cov ntsiab lus no, txuas ntxiv yog siv rau hauv kev nkag siab dav dav los txhais tau tias "extends" (xws li hauv cov chav kawm) lossis "ua" (xws li hauv kev sib tshuam).

Dab tsi yog wildcard hauv generics hauv Java?

Java Generic's wildcards yog ib tug mechanism nyob rau hauv Java Generics tsom rau kev ua kom nws muaj peev xwm pov tau ib qho kev sau ntawm ib chav kawm, xws li A, mus rau ib qho kev sau ntawm subclass lossis superclass ntawm A.

Pom zoo: