Thayipha Izichasiselo ku-Java

Thayipha Izichasiselo ku-Java

Ngokwethulwa kwe-Java 8, inguqulo yethule izici ezimbili ezintsha ezibizwa ngokuthi izichasiselo eziphindayo kanye nezichasiselo zohlobo. Kuze kube yilesi sikhathi, uma ubufuna ukusebenzisa izichasiselo ku-Java, ubungenza lokho kuphela kuzimemezelo. Nge-Java 8, manje ungakwazi ukwengeza izichasiselo kunoma yiluphi uhlobo lokusetshenziswa. Nomaphi lapho usebenzisa uhlobo (okuhlanganisa izinhlobo ezimemezelweni, ezijwayelekile, nabalingisi), ungakuphelezela lokho ngesichasiselo.

Thayipha i-Syntax yesichasiselo

I-Java 8 ingamemezela izichasiselo zohlobo kunoma yiluphi uhlobo lokusetshenziswa. Isibonelo esisodwa amazwibela angezansi:

@Idatha Yentambo Ebethelwe; Faka ohlwini <@NonNull String> izintambo; myGraph = ( @Igrafu engaguquki ) tmpGraph; Ungakwazi kalula ukwethula uhlobo olusha isichasiselo. Inqubo ifana nokuchaza isichasiselo esinethagethi ye-ElementType.TYPE_PARAMETER, ElementType.TYPE_USE, noma kokubili okuqondiwe: @Target ( { ElementType.TYPE_PARAMETER, ElementType.TYPE_USE } ) esidlangalaleni @i-interface Ebethelwe { }

Ithagethi ye-ElementType.TYPE_PARAMETER isho ukuthi ungakwazi ukubhala isichasiselo esimemezelweni sohlobo oluguquguqukayo (isb. ikilasi elithi MyClass {….}). I-Element.Type.TYPE_USE isho ukuthi ungakwazi ukubhala isichasiselo kunoma yiluphi uhlobo lokusetshenziswa (okungukuthi izinhlobo zezimemezelo, ezijwayelekile, kanye nabalingisi).

Ungagcina izichasiselo kumafayela ekilasi, kodwa akuthinti noma kube nomthelela ekusebenzeni kohlelo. Njengesibonelo, ungamemezela okuguquguqukayo kwefayela okubili kanye nokuxhumana njengoba kukhonjisiwe kukhodi engezansi:

Ifayela lefayela = ….; @Encryted File encryptedFile = …; @Vula Uxhumano Lokuxhumana = …; Ngenkathi wenza uhlelo, umphumela uzofana uma udlulisela elinye lamafayela amabili endleleni yokuthumela () yokuxhuma. uxhumano.thumela(ifayela); connection.send(encryptedFile);

 

Ezinye Izibonelo Zezichasiselo Zohlobo

@nonnull List Faka ohlwini <@NonNull String> str Arrays <@NonNegative Integer> hlunga @Ifayela Lefayela Elifihliwe @Vula Uxhumano lwe-void divideInteger (int a, int b) uphonsa @ZeroDivisior ArithmeticException

 

Shiya amazwana

Le sayithi isebenzisa i-Akismet ukunciphisa ugaxekile. Funda ukuthi idatha yakho yokuphawula isetshenziswa kanjani.