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>
                            主站蜘蛛池模板: 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | 颗粒机,颗粒机组,木屑颗粒机-济南劲能机械有限公司 | 欧版反击式破碎机-欧版反击破-矿山石料破碎生产线-青州奥凯诺机械 | 浙江筋膜枪-按摩仪厂家-制造商-肩颈按摩仪哪家好-温州市合喜电子科技有限公司 | 英国公司注册-新加坡公司注册-香港公司开户-离岸公司账户-杭州商标注册-杭州优创企业 | 北京开业庆典策划-年会活动策划公司-舞龙舞狮团大鼓表演-北京盛乾龙狮鼓乐礼仪庆典策划公司 | 破碎机锤头_合金耐磨锤头_郑州宇耐机械工程技术有限公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 船用锚链|专业锚链生产厂家|安徽亚太锚链制造有限公司 | 中国产业发展研究网 - 提供行业研究报告 可行性研究报告 投资咨询 市场调研服务 | 安全,主动,被动,柔性,山体滑坡,sns,钢丝绳,边坡,防护网,护栏网,围栏,栏杆,栅栏,厂家 - 护栏网防护网生产厂家 | 压接机|高精度压接机|手动压接机|昆明可耐特科技有限公司[官网] 胶泥瓷砖胶,轻质粉刷石膏,嵌缝石膏厂家,腻子粉批发,永康家德兴,永康市家德兴建材厂 | 工业洗衣机_工业洗涤设备_上海力净工业洗衣机厂家-洗涤设备首页 bkzzy在职研究生网 - 在职研究生招生信息咨询平台 | 电镀电源整流器_高频电解电源_单脉双脉冲电源 - 东阳市旭东电子科技 | 专业广州网站建设,微信小程序开发,一物一码和NFC应用开发、物联网、外贸商城、定制系统和APP开发【致茂网络】 | 钢板仓,大型钢板仓,钢板库,大型钢板库,粉煤灰钢板仓,螺旋钢板仓,螺旋卷板仓,骨料钢板仓 | 大巴租车平台承接包车,通勤班车,巴士租赁业务 - 鸿鸣巴士 | 金联宇电缆总代理-金联宇集团-广东金联宇电缆实业有限公司 | 一礼通 (www.yilitong.com)-企业礼品解决方案一站式服务平台 | 洛阳永磁工业大吊扇研发生产-工厂通风降温解决方案提供商-中实洛阳环境科技有限公司 | 干洗店加盟_洗衣店加盟_干洗店设备-伊蔻干洗「武汉总部」 | 陕西鹏展科技有限公司 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 压力变送器-上海武锐自动化设备有限公司 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 识禅_对禅的了解,从这里开始 | 尊享蟹太太美味,大闸蟹礼卡|礼券|礼盒在线预订-蟹太太官网 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | 合肥宠物店装修_合肥宠物美容院装修_合肥宠物医院设计装修公司-安徽盛世和居装饰 | 硫化罐-电加热蒸汽硫化罐生产厂家-山东鑫泰鑫智能装备有限公司 | 运动木地板厂家,篮球场木地板品牌,体育场馆木地板安装 - 欧氏运动地板 | 润东方环保空调,冷风机,厂房车间降温设备-20年深圳环保空调生产厂家 | 碎石机设备-欧版反击破-欧版颚式破碎机(站)厂家_山东奥凯诺机械 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 上海冠顶工业设备有限公司-隧道炉,烘箱,UV固化机,涂装设备,高温炉,工业机器人生产厂家 | 儿童乐园|游乐场|淘气堡招商加盟|室内儿童游乐园配套设备|生产厂家|开心哈乐儿童乐园 | (中山|佛山|江门)环氧地坪漆,停车场地板漆,车库地板漆,聚氨酯地板漆-中山永旺地坪漆厂家 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 直线模组_滚珠丝杆滑台_模组滑台厂家_万里疆科技 | 自动配料系统_称重配料控制系统厂家 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 仪器仪表网 - 永久免费的b2b电子商务平台|