首页 > 编程知识 正文

@repeatable注解

时间:2023-05-06 18:51:53 阅读:177844 作者:115

元注释@Repeatable限定的注释可以在同一个位置多次使用。 这是JAVA8添加的新功能,在此之前,注释只能在同一个地方使用一次(实际上有解决方案,但可读性不好)。 使用@Repeatable时,类对象(class对象)容器包含value方法,其中@Repeatable @Repeatable的参数是需要重用的注释限定注释的容器通过返回限定注释的数组完成可复用注释的定义,并在相应的类、方法中添加importstaticjava.lang.annotation.element type.method; import Java.lang.annotation.repeatable; import Java.lang.annotation.retention; import Java.lang.annotation.retention policy; import Java.lang.annotation.target; 公共类文件{ @ target (method ) retention ) retentionpolicy.runtime (公共@ interface filetype s ) filetype )。 //对应3}@target(method ) retention ) retentionpolicy.runtime ) repeatable ) filetypes.class ) /对应1,2 public @ intimime @filetype('.Java ' ) filetype ) '.html ' ) filetype ) '.CSS ' ) filetype ) '.js ' ) publicvoidwork ) { try }系统文件类型文件:文件类型s ) system.out.println (filetype.value (); }System.out.println (搜索过程缩写。 我想知道请参阅。 ); } catch (nosuchmethodexception )/todo auto-generatedcatchblocke.print stack trace ); } publicstaticvoidmain (string [ ] args ) {newFindFiles ) ).work ); }其中FileType是要重用的注释,FileTypes是容器。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。