E ʻano i nā ʻōlelo hōʻike ma Java

E ʻano i nā ʻōlelo hōʻike ma Java

Me ka hoʻomaka ʻana o Java 8, ua hoʻokomo ka mana i ʻelua mau hiʻohiʻona hou i kapa ʻia ʻo ka hoʻihoʻi ʻana i nā annotations a me nā ʻano annotations. A hiki i kēia manawa, inā makemake ʻoe e hoʻohana i nā annotation ma Java, hiki iā ʻoe ke hana pēlā ma nā ʻōlelo hoʻolaha. Me Java 8, hiki iā ʻoe ke hoʻohui i nā annotations i kēlā me kēia ʻano hoʻohana. Ma nā wahi a pau āu e hoʻohana ai i kahi ʻano (me nā ʻano i loko o nā ʻōlelo hoʻolaha, generics, a me nā casts), hiki iā ʻoe ke hoʻopili me ia me kahi hōʻike.

ʻAno ʻAno Hōʻike Syntax

Hiki i ka Java 8 ke haʻi aku i nā ʻano annotations ma kekahi ʻano hoʻohana. ʻO kekahi laʻana ka snippet ma lalo nei:

@Encrypted string data; E papa inoa <@NonNull String> nā kaula; myGraph = ( @Immutable Graph ) tmpGraph; Hiki iā ʻoe ke hoʻokomo i kahi hōʻike ʻano hou. Ua like ke kaʻina hana me ka wehewehe ʻana i kahi hōʻike me ka ElementType.TYPE_PARAMETER pahu hopu, ElementType.TYPE_USE pahu hopu, a i ʻole nā ​​pahuhopu ʻelua: @Target ( { ElementType.TYPE_PARAMETER, ElementType.TYPE_USE } ) lehulehu @interface Encrypted { }

ʻO ka ElementType.TYPE_PARAMETER pahu hopu e hōʻike ana e hiki iā ʻoe ke kākau i ka hōʻike ma ka haʻi ʻana o kahi ʻano loli (e laʻa me ka papa MyClass {….}). ʻO ka Element.Type.TYPE_USE e hōʻike ana e hiki iā ʻoe ke kākau i ka hōʻike ma kekahi ʻano hoʻohana (ʻo ia hoʻi nā ʻano i nā ʻōlelo hoʻolaha, generics, a me nā kiola).

Hiki iā ʻoe ke mālama i nā annotation i loko o nā faila papa, akā ʻaʻole ia e hoʻopilikia a hoʻoikaika paha i ka hoʻokō ʻana o ka papahana. No ka laʻana, hiki iā ʻoe ke haʻi aku i ʻelua mau faila a me kahi pilina e like me ka mea i hōʻike ʻia ma ke code ma lalo nei:

waihona waihona = ….; @File i hoʻopili ʻia i hoʻopili ʻia = …; @Open Connection hono = …; ʻOiai ʻoe e hoʻokō nei i ka papahana, e like ana ka hopena inā e hāʻawi ʻoe i kekahi o nā faila ʻelua i ke ala hoʻouna () pili. connection.send(file); connection.send(encryptedFile);

 

ʻO kekahi mau laʻana o nā ʻano hōʻike

@nonNull Papa inoa Papa inoa <@NonNull String> str Arrays <@NonNegative Integer> sort @Encypted File file @Open Connection connection void divideInteger (int a, int b) throws @ZeroDivisior ArithmeticException

 

Waiho i ka manaʻo hoʻopuka

Ke hoʻohana nei kēia pūnaewele i ka Akismet e ho'ēmi i ka spam. E aʻo pehea e hanaʻia ai kāuʻikeʻikepili.