pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='Xy6lW'></tfoot>
    <i id='Xy6lW'><tr id='Xy6lW'><dt id='Xy6lW'><q id='Xy6lW'><span id='Xy6lW'><b id='Xy6lW'><form id='Xy6lW'><ins id='Xy6lW'></ins><ul id='Xy6lW'></ul><sub id='Xy6lW'></sub></form><legend id='Xy6lW'></legend><bdo id='Xy6lW'><pre id='Xy6lW'><center id='Xy6lW'></center></pre></bdo></b><th id='Xy6lW'></th></span></q></dt></tr></i><div class="i7gmdxw" id='Xy6lW'><tfoot id='Xy6lW'></tfoot><dl id='Xy6lW'><fieldset id='Xy6lW'></fieldset></dl></div>

    <small id='Xy6lW'></small><noframes id='Xy6lW'>

  • <legend id='Xy6lW'><style id='Xy6lW'><dir id='Xy6lW'><q id='Xy6lW'></q></dir></style></legend>

      <bdo id='Xy6lW'></bdo><ul id='Xy6lW'></ul>

        一個元素上有多個相同類型的注釋?

        Multiple annotations of the same type on one element?(一個元素上有多個相同類型的注釋?)

          1. <small id='XpOKT'></small><noframes id='XpOKT'>

                <bdo id='XpOKT'></bdo><ul id='XpOKT'></ul>
                    <tbody id='XpOKT'></tbody>
                  <tfoot id='XpOKT'></tfoot>
                1. <i id='XpOKT'><tr id='XpOKT'><dt id='XpOKT'><q id='XpOKT'><span id='XpOKT'><b id='XpOKT'><form id='XpOKT'><ins id='XpOKT'></ins><ul id='XpOKT'></ul><sub id='XpOKT'></sub></form><legend id='XpOKT'></legend><bdo id='XpOKT'><pre id='XpOKT'><center id='XpOKT'></center></pre></bdo></b><th id='XpOKT'></th></span></q></dt></tr></i><div class="kbirrlu" id='XpOKT'><tfoot id='XpOKT'></tfoot><dl id='XpOKT'><fieldset id='XpOKT'></fieldset></dl></div>

                2. <legend id='XpOKT'><style id='XpOKT'><dir id='XpOKT'><q id='XpOKT'></q></dir></style></legend>
                3. 本文介紹了一個元素上有多個相同類型的注釋?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我試圖在單個元素上添加兩個或多個相同類型的注釋,在本例中是一個方法.這是我正在使用的大致代碼:

                  public class Dupe {公共@interface Foo {字符串條();}@Foo(bar="one")@Foo(bar="兩個")公共無效哈哈(){}}

                  編譯上面的時候,javac報錯注解:

                  <上一頁>max@upsight:~/work/daybreak$ javac Dupe.javaDupe.java:5:重復注釋

                  難道就不能像這樣重復注釋嗎?學究起來,上面的兩個@Foo 實例不是因為內容不同而不同嗎?

                  如果上述方法不可行,有哪些潛在的解決方法?

                  更新:我被要求描述我的用例.來了.

                  我正在構建一種語法糖化機制,將 POJO映射"到 MongoDB 等文檔存儲.我想允許將索引指定為 getter 或 setter 上的注釋.這是一個人為的例子:

                  公共類員工{私人名單<項目>項目;@Index(expr = "project.client_id")@Index(expr = "project.start_date")公開列表<項目>getProjects() { 返回項目;}}

                  顯然,我希望能夠通過 Project 的各種屬性快速找到 Employee 的實例.我可以使用不同的 expr() 值指定 @Index 兩次,或者采用接受的答案中指定的方法.盡管 Hibernate 做到了這一點并且它不被認為是 hack,但我認為至少允許在單個元素上具有多個相同類型的注釋仍然是有意義的.

                  解決方案

                  注意:由于 Java 8 引入了 @Repeatable 批注(請參閱 @mernst 的回答),此答案已部分過時.但是仍然需要 @Foos 容器注釋和專用處理.

                  不允許使用兩個或多個相同類型的注釋.但是,您可以這樣做:

                  public @interface Foos {Foo[] 值();}//Java 8 之前@Foos({@Foo(bar=一個"), @Foo(bar=兩個")})公共無效哈哈(){}//在@Foo 上發布帶有@Repeatable(Foos.class) 的Java 8@Foo(bar=一個") @Foo(bar=兩個")公共無效哈哈(){}

                  您需要專門處理代碼中的 Foos 注釋.

                  I'm attempting to slap two or more annotations of the same type on a single element, in this case, a method. Here's the approximate code that I'm working with:

                  public class Dupe {
                      public @interface Foo {
                        String bar();
                      }
                  
                      @Foo(bar="one")
                      @Foo(bar="two")
                      public void haha() {}
                  }
                  

                  When compiling the above, javac complains about a duplicate annotation:

                  max@upsight:~/work/daybreak$ javac Dupe.java 
                  Dupe.java:5: duplicate annotation
                  

                  Is it simply not possible to repeat annotations like this? Pedantically speaking, aren't the two instances of @Foo above different due to their contents being different?

                  If the above isn't possible, what are some potential workarounds?

                  UPDATE: I've been asked to describe my use case. Here goes.

                  I'm building a syntax sugarish mechanism to "map" POJOs to document stores such as MongoDB. I want to allow indexes to be specified as annotations on the getters or setters. Here's a contrived example:

                  public class Employee {
                      private List<Project> projects;
                  
                      @Index(expr = "project.client_id")
                      @Index(expr = "project.start_date")
                      public List<Project> getProjects() { return projects; }
                  }
                  

                  Obviously, I want to be able to quickly find instances of Employee by various properties of Project. I can either specify @Index twice with different expr() values, or take the approach specified in the accepted answer. Even though Hibernate does this and it's not considered a hack, I think it still makes sense to at least allow having multiple annotations of the same type on a single element.

                  解決方案

                  Note: This answer is partially outdated since Java 8 introduced the @Repeatable annotation (see answer by @mernst). The need for a @Foos container annotation and dedicated handling still remain though.

                  Two or more annotations of same type aren't allowed. However, you could do something like this:

                  public @interface Foos {
                      Foo[] value();
                  }
                  
                  // pre Java 8
                  @Foos({@Foo(bar="one"), @Foo(bar="two")})
                  public void haha() {}
                  
                  // post Java 8 with @Repeatable(Foos.class) on @Foo
                  @Foo(bar="one") @Foo(bar="two")
                  public void haha() {}
                  

                  You'll need dedicated handling of Foos annotation in code though.

                  這篇關于一個元素上有多個相同類型的注釋?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)

                  • <bdo id='DvNJr'></bdo><ul id='DvNJr'></ul>
                      <tbody id='DvNJr'></tbody>
                    <i id='DvNJr'><tr id='DvNJr'><dt id='DvNJr'><q id='DvNJr'><span id='DvNJr'><b id='DvNJr'><form id='DvNJr'><ins id='DvNJr'></ins><ul id='DvNJr'></ul><sub id='DvNJr'></sub></form><legend id='DvNJr'></legend><bdo id='DvNJr'><pre id='DvNJr'><center id='DvNJr'></center></pre></bdo></b><th id='DvNJr'></th></span></q></dt></tr></i><div class="yunegfh" id='DvNJr'><tfoot id='DvNJr'></tfoot><dl id='DvNJr'><fieldset id='DvNJr'></fieldset></dl></div>

                        <small id='DvNJr'></small><noframes id='DvNJr'>

                          1. <tfoot id='DvNJr'></tfoot>
                          2. <legend id='DvNJr'><style id='DvNJr'><dir id='DvNJr'><q id='DvNJr'></q></dir></style></legend>
                            主站蜘蛛池模板: 西子馋火锅鸡加盟-太原市龙城酉鼎餐饮管理有限公司 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 粘度计维修,在线粘度计,二手博勒飞粘度计维修|收购-天津市祥睿科技有限公司 | 首页|成都尚玖保洁_家政保洁_开荒保洁_成都保洁 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 废气处理设备-工业除尘器-RTO-RCO-蓄热式焚烧炉厂家-江苏天达环保设备有限公司 | 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | 大立教育官网-一级建造师培训-二级建造师培训-造价工程师-安全工程师-监理工程师考试培训 | 高考志愿规划师_高考规划师_高考培训师_高报师_升学规划师_高考志愿规划师培训认证机构「向阳生涯」 | 钢制暖气片散热器_天津钢制暖气片_卡麦罗散热器厂家 | 打包箱房_集成房屋-山东佳一集成房屋有限公司 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂 | 嘉兴恒升声级计-湖南衡仪声级计-杭州爱华多功能声级计-上海邦沃仪器设备有限公司 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 金刚网,金刚网窗纱,不锈钢网,金刚网厂家- 河北萨邦丝网制品有限公司 | 商秀—企业短视频代运营_抖音企业号托管 | 江西自考网| (中山|佛山|江门)环氧地坪漆,停车场地板漆,车库地板漆,聚氨酯地板漆-中山永旺地坪漆厂家 | 防爆大气采样器-防爆粉尘采样器-金属粉尘及其化合物采样器-首页|盐城银河科技有限公司 | vr安全体验馆|交通安全|工地安全|禁毒|消防|安全教育体验馆|安全体验教室-贝森德(深圳)科技 | 千淘酒店差旅平台-中国第一家针对TMC行业的酒店资源供应平台 | 连栋温室大棚建造厂家-智能玻璃温室-薄膜温室_青州市亿诚农业科技 | 山东氧化铁红,山东铁红-淄博科瑞化工有限公司 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 活性炭厂家-蜂窝活性炭-粉状/柱状/果壳/椰壳活性炭-大千净化-活性炭 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 济南展厅设计施工_数字化展厅策划设计施工公司_山东锐尚文化传播有限公司 | 成都顶呱呱信息技术有限公司-贷款_个人贷款_银行贷款在线申请 - 成都贷款公司 | 玉米深加工设备|玉米加工机械|玉米加工设备|玉米深加工机械-河南成立粮油机械有限公司 | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂_帽子厂_浙江高普制帽厂 | ★塑料拖链__工程拖链__电缆拖链__钢制拖链 - 【上海闵彬】 | 中央空调维修、中央空调保养、螺杆压缩机维修-苏州东菱空调 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 南京展台搭建-南京展会设计-南京展览设计公司-南京展厅展示设计-南京汇雅展览工程有限公司 | 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 | EPDM密封胶条-EPDM密封垫片-EPDM生产厂家 | 有源电力滤波装置-电力有源滤波器-低压穿排电流互感器|安科瑞 |