• <i id='INkMZ'><tr id='INkMZ'><dt id='INkMZ'><q id='INkMZ'><span id='INkMZ'><b id='INkMZ'><form id='INkMZ'><ins id='INkMZ'></ins><ul id='INkMZ'></ul><sub id='INkMZ'></sub></form><legend id='INkMZ'></legend><bdo id='INkMZ'><pre id='INkMZ'><center id='INkMZ'></center></pre></bdo></b><th id='INkMZ'></th></span></q></dt></tr></i><div id='INkMZ'><tfoot id='INkMZ'></tfoot><dl id='INkMZ'><fieldset id='INkMZ'></fieldset></dl></div>
    1. <legend id='INkMZ'><style id='INkMZ'><dir id='INkMZ'><q id='INkMZ'></q></dir></style></legend>

    2. <tfoot id='INkMZ'></tfoot>

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

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

        如何在注解中使用数组常量

        时间:2023-07-26

          <tfoot id='mLw07'></tfoot>

          • <i id='mLw07'><tr id='mLw07'><dt id='mLw07'><q id='mLw07'><span id='mLw07'><b id='mLw07'><form id='mLw07'><ins id='mLw07'></ins><ul id='mLw07'></ul><sub id='mLw07'></sub></form><legend id='mLw07'></legend><bdo id='mLw07'><pre id='mLw07'><center id='mLw07'></center></pre></bdo></b><th id='mLw07'></th></span></q></dt></tr></i><div id='mLw07'><tfoot id='mLw07'></tfoot><dl id='mLw07'><fieldset id='mLw07'></fieldset></dl></div>
            <legend id='mLw07'><style id='mLw07'><dir id='mLw07'><q id='mLw07'></q></dir></style></legend>
                <tbody id='mLw07'></tbody>

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

              • <bdo id='mLw07'></bdo><ul id='mLw07'></ul>
                  本文介绍了如何在注解中使用数组常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想为注释值使用常量.

                  I would like to use constants for annotation values.

                  interface Client {
                  
                      @Retention(RUNTIME)
                      @Target(METHOD)
                      @interface SomeAnnotation { String[] values(); }
                  
                      interface Info {
                          String A = "a";
                          String B = "b";
                          String[] AB = new String[] { A, B };
                      }
                  
                      @SomeAnnotation(values = { Info.A, Info.B })
                      void works();
                  
                      @SomeAnnotation(values = Info.AB)
                      void doesNotWork();
                  }
                  

                  常量 Info.AInfo.B 可以在注解中使用,但不能在数组 Info.AB 中使用,因为它必须在这个地方做一个数组初始化器.注释值仅限于可以内联到类的字节码中的值.这对于数组常量是不可能的,因为它必须在加载 Info 时构建.这个问题有解决办法吗?

                  The constants Info.A and Info.B can be used in the annotation but not the array Info.AB as it has to be an array initializer in this place. Annotation values are restricted to values that could be inlined into the byte code of a class. This is not possible for the array constant as it has to be constructed when Info is loaded. Is there a workaround for this problem?

                  推荐答案

                  不,没有解决方法.

                  这篇关于如何在注解中使用数组常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:什么是默认注释处理器发现过程? 下一篇:JSF 2 使用 @ManagedProperty 注入 Spring bean/service 而没

                  相关文章

                  最新文章

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

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

                      <tfoot id='NOXgc'></tfoot>
                      <i id='NOXgc'><tr id='NOXgc'><dt id='NOXgc'><q id='NOXgc'><span id='NOXgc'><b id='NOXgc'><form id='NOXgc'><ins id='NOXgc'></ins><ul id='NOXgc'></ul><sub id='NOXgc'></sub></form><legend id='NOXgc'></legend><bdo id='NOXgc'><pre id='NOXgc'><center id='NOXgc'></center></pre></bdo></b><th id='NOXgc'></th></span></q></dt></tr></i><div id='NOXgc'><tfoot id='NOXgc'></tfoot><dl id='NOXgc'><fieldset id='NOXgc'></fieldset></dl></div>
                    1. <legend id='NOXgc'><style id='NOXgc'><dir id='NOXgc'><q id='NOXgc'></q></dir></style></legend>