Nyora Annotations muJava

Nyora Annotations muJava

Nekuunzwa kweJava 8, iyo vhezheni yakaunza maviri matsva maficha anonzi kudzokorora zvirevo uye mhando zvirevo. Kusvika panguva ino, kana iwe uchida kushandisa zvirevo muJava, waigona chete kuzviita mune zviziviso. NeJava 8, ikozvino unogona kuwedzera zvirevo kune chero mhando yekushandisa. Pese pauri kushandisa mhando (inosanganisira mhando dzezviziviso, jenariki, uye makanda), unogona kuperekedza izvozvo neanotsidzira.

Nyora Annotation Syntax

Java 8 inogona kuzivisa zvinyorwa zvemhando pane chero mhando yekushandisa. Mumwe muenzaniso ndeye snippet pazasi:

@Encrypted String data; Rondedzera <@NonNull String> tambo; myGraph = ( @Immutable Graph ) tmpGraph; Iwe unogona kungo suma rudzi rutsva rondedzero. Kuita kwakafanana nekutsanangura dudziro ine ElementType.TYPE_PARAMETER tarisiro, ElementType.TYPE_USE tarisiro, kana zvese zvinonangwa: @Target ( { ElementType.TYPE_PARAMETER, ElementType.TYPE_USE } ) public @interface Encrypted { }

The ElementType.TYPE_PARAMETER tarisiro inoratidza kuti unokwanisa kunyora chirevo pane chiziviso cherudzi rwakasiyana (semuenzaniso kirasi MyClass {….}). The Element.Type.TYPE_USE zvinoreva kuti unokwanisa kunyora chirevo cherudzi rwupi zvarwo rwemashandisirwo (kureva marudzi muzviziviso, jenariki, uye akakasa).

Unogona kuchengetedza zvirevo mumafaira ekirasi, asi hazvikanganise kana kukanganisa maitirwo echirongwa. Semuenzaniso, unogona kuzivisa maviri mafaera akasiyana uye chinongedzo sezvakaratidzwa mukodhi pazasi:

Faira faira = ....; @Encryted File encryptedFile = …; @Vhura Connection yekubatanidza = ...; Paunenge uchiita chirongwa, mhedzisiro ichave yakafanana kana iwe ukapfuura imwe yemafaira maviri kune yekubatanidza's send() nzira. connection.send(file); connection.send(encryptedFile);

 

Mimwe Mienzaniso Yemhando Yezvinyorwa

@nonNull List Rondedzera <@NonNull String> str Arrays <@NonNegative Integer> rongedza @Encypted Faira faira @Open Connection yekubatanidza void divideInteger (int a, int b) inokanda @ZeroDivisior ArithmeticException

 

Leave mhinduro

Nzvimbo iyi inoshandisa Akismet kuderedza spam. Dzidza kuti sei deta yako inoshandiswa.