Dab tsi yog generics hauv Java thiab nws ua haujlwm li cas?
Dab tsi yog generics hauv Java thiab nws ua haujlwm li cas?

Video: Dab tsi yog generics hauv Java thiab nws ua haujlwm li cas?

Video: Dab tsi yog generics hauv Java thiab nws ua haujlwm li cas?
Video: Cupra Formentor 2021 test drive and launch control in feature film format. Seat Group 2024, Kaum ib hlis
Anonim

Cov Java Generics programming yog qhia hauv J2SE 5 los cuam tshuam nrog cov khoom zoo. Nws ua rau cov cai ruaj khov bydetecting cov kab ntawm compile lub sij hawm. Ua ntej cov generics , peb tuaj yeem khaws txhua yam khoom hauv kev sau, piv txwv li, tsis- muaj . Tam sim no cov generics quab yuam java ua programmer khaws ib hom khoom tshwj xeeb.

Ib sab ntawm qhov no, dab tsi yog kev siv generics hauv Java?

Ntau yam tso cai rau ib hom lossis txoj hauv kev ua haujlwm onobjects ntawm ntau hom thaum muab compile-time hom kev nyab xeeb, ua Java ib hom lus statically ntaus ntawv tag nrho. Ntau yam yog ib qho kev tsis sib haum xeeb tshaj plaws Java yam lus.

Qhov thib ob, T hom java yog dab tsi? < T > tshwj xeeb stands for generic hom . Raws li Java Docs - Ib qho yooj yim hom yog ib chav kawm generic lossis interface uas yog parameterized tshaj hom. Cia kuv pib nrog piv txwv: Xav txog ib lub thawv hom uas hastwo txoj kev uas yog siv los teem thiab tau cov khoom.

Raws li, dab tsi yog txhais los ntawm lo lus generics hauv Java?

“ Java Generics yog ib tug technical lub sij hawm denoting ib pawg lus nta muaj feem xyuam rau lub txhais thiab siv muaj hom thiab txoj kev. Hauv java ua , Ntau hom lossis txoj kev sib txawv ntawm cov hom tsis tu ncua thiab txoj hauv kev uas lawv muaj hom tsis muaj.

Yuav ua li cas generics yog siv nyob rau hauv Java?

Rau siv generics , cov Java compilerapplies hom erasure rau: Hloov txhua hom tsis nyob rau hauv muaj hom nrog lawv cov bounds los yog Object yog tias cov typeparameters yog unbounded. Tus tsim bytecode, yog li ntawd, tsuas muaj cov chav kawm zoo tib yam, interfaces, thiab cov txheej txheem.

Pom zoo: