Cov txheej txheem:

Daim ntawv teev npe dav dav hauv Java yog dab tsi?
Daim ntawv teev npe dav dav hauv Java yog dab tsi?

Video: Daim ntawv teev npe dav dav hauv Java yog dab tsi?

Video: Daim ntawv teev npe dav dav hauv Java yog dab tsi?
Video: tos koj hauv nruab dab - nuj xeem - nkauj tawm tshiab fullMV 2021 2024, Kaum ib hlis
Anonim

Generic List hauv Java . Hauv lwm lo lus, piv txwv ntawm Sau npe tuaj yeem muab tau ib hom, yog li tsuas yog piv txwv ntawm hom ntawd tuaj yeem muab tso thiab nyeem los ntawm qhov ntawd Sau npe . Nov yog ib qho piv txwv: Sau npe = tshiab ArrayList; Qhov no lis yog tam sim no tsom rau tsuas yog String piv txwv, txhais tau tias tsuas yog String piv txwv tuaj yeem muab tso rau hauv qhov no lis

Ua raws li qhov no hauv kev txiav txim siab, koj txhais li cas cov npe generic hauv Java?

Java tau muab kev txhawb nqa dav dav hauv List interface

  1. Syntax. Sau npe = tshiab ArrayList();
  2. Kev piav qhia. Tus T yog ib hom parameter kis mus rau generic interface List thiab nws cov chav kawm ArrayList.
  3. Piv txwv. Tsim cov java program hauv qab no siv cov editor ntawm koj xaiv.
  4. Tso zis.

Ib sab saum toj no, dab tsi yog cov khoom sau hauv Java? Cov Java Generics programming yog qhia hauv J2SE 5 los cuam tshuam nrog cov khoom zoo. Nws ua rau cov cai ruaj khov los ntawm kev txheeb xyuas cov kab mob ntawm lub sijhawm sib sau. Ua ntej cov generics , peb tuaj yeem khaws txhua yam khoom hauv lub sau , i.e., tsis- muaj . Tam sim no cov generics quab yuam java ua programmer khaws ib hom khoom tshwj xeeb.

Ib yam li ib tug yuav nug, dab tsi yog hom generic hauv Java?

Txhais: “A hom hom yog a chav kawm dav dav los yog interface uas yog parameterized dhau hom ” Qhov tseem ceeb, hom generic cia koj sau ib tug general, chav kawm dav dav (los yog txoj kev) uas ua haujlwm nrog sib txawv hom , tso cai rau rov siv dua code.

Daim ntawv teev npe yog dab tsi?

Daim Ntawv Teev Npe yog a muaj sau hauv C#. Qhov loj tuaj yeem siv tau dynamically Sau npe , tsis zoo li Arrays. Cia peb pom ib qho piv txwv - Peb tau teeb tsa Sau npe thawj- Sau npe myList = new Sau npe ()

Pom zoo: