久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      <tfoot id='zdh55'></tfoot>

      1. <legend id='zdh55'><style id='zdh55'><dir id='zdh55'><q id='zdh55'></q></dir></style></legend>

        Java 尋找具有特定注解的方法及其注解元素

        Java seek a method with specific annotation and its annotation element(Java 尋找具有特定注解的方法及其注解元素)
          <legend id='ymxdI'><style id='ymxdI'><dir id='ymxdI'><q id='ymxdI'></q></dir></style></legend>
            <tbody id='ymxdI'></tbody>

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

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

          1. <tfoot id='ymxdI'></tfoot>

              • <bdo id='ymxdI'></bdo><ul id='ymxdI'></ul>
                • 本文介紹了Java 尋找具有特定注解的方法及其注解元素的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  Suppose I have this annotation class

                  
                  @Retention(RetentionPolicy.RUNTIME)
                  @Target(ElementType.METHOD)
                  public @interface MethodXY {
                      public int x();
                      public int y();
                  }
                  
                  public class AnnotationTest {
                      @MethodXY(x=5, y=5)
                      public void myMethodA(){ ... }
                  
                      @MethodXY(x=3, y=2)
                      public void myMethodB(){ ... }
                  }
                  

                  So is there a way to look into an object, "seek" out the method with the @MethodXY annotation, where its element x = 3, y = 2, and invoke it?

                  Thanks

                  解決方案

                  Here is a method, which returns methods with specific annotations:

                  public static List<Method> getMethodsAnnotatedWith(final Class<?> type, final Class<? extends Annotation> annotation) {
                      final List<Method> methods = new ArrayList<Method>();
                      Class<?> klass = type;
                      while (klass != Object.class) { // need to iterated thought hierarchy in order to retrieve methods from above the current instance
                          // iterate though the list of methods declared in the class represented by klass variable, and add those annotated with the specified annotation
                          for (final Method method : klass.getDeclaredMethods()) {
                              if (method.isAnnotationPresent(annotation)) {
                                  Annotation annotInstance = method.getAnnotation(annotation);
                                  // TODO process annotInstance
                                  methods.add(method);
                              }
                          }
                          // move to the upper class in the hierarchy in search for more methods
                          klass = klass.getSuperclass();
                      }
                      return methods;
                  }
                  

                  It can be easily modified to your specific needs. Pls note that the provided method traverses class hierarchy in order to find methods with required annotations.

                  Here is a method for your specific needs:

                  public static List<Method> getMethodsAnnotatedWithMethodXY(final Class<?> type) {
                      final List<Method> methods = new ArrayList<Method>();
                      Class<?> klass = type;
                      while (klass != Object.class) { // need to iterated thought hierarchy in order to retrieve methods from above the current instance
                          // iterate though the list of methods declared in the class represented by klass variable, and add those annotated with the specified annotation
                          for (final Method method : klass.getDeclaredMethods()) {
                              if (method.isAnnotationPresent(MethodXY.class)) {
                                  MethodXY annotInstance = method.getAnnotation(MethodXY.class);
                                  if (annotInstance.x() == 3 && annotInstance.y() == 2) {         
                                      methods.add(method);
                                  }
                              }
                          }
                          // move to the upper class in the hierarchy in search for more methods
                          klass = klass.getSuperclass();
                      }
                      return methods;
                  }
                  

                  For invocation of the found method(s) pls refer a tutorial. One of the potential difficulties here is the number of method arguments, which could vary between found methods and thus requiring some additional processing.

                  這篇關(guān)于Java 尋找具有特定注解的方法及其注解元素的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯(cuò)誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語(yǔ)句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數(shù)的三元表達(dá)式的類(lèi)型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲(chǔ)出現(xiàn)的每個(gè)字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉(zhuǎn)換 char 原語(yǔ)?)
                  <i id='0s2e9'><tr id='0s2e9'><dt id='0s2e9'><q id='0s2e9'><span id='0s2e9'><b id='0s2e9'><form id='0s2e9'><ins id='0s2e9'></ins><ul id='0s2e9'></ul><sub id='0s2e9'></sub></form><legend id='0s2e9'></legend><bdo id='0s2e9'><pre id='0s2e9'><center id='0s2e9'></center></pre></bdo></b><th id='0s2e9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0s2e9'><tfoot id='0s2e9'></tfoot><dl id='0s2e9'><fieldset id='0s2e9'></fieldset></dl></div>

                  <legend id='0s2e9'><style id='0s2e9'><dir id='0s2e9'><q id='0s2e9'></q></dir></style></legend>
                  <tfoot id='0s2e9'></tfoot>
                          <tbody id='0s2e9'></tbody>

                        • <bdo id='0s2e9'></bdo><ul id='0s2e9'></ul>

                            <small id='0s2e9'></small><noframes id='0s2e9'>

                            主站蜘蛛池模板: 黄色av网站免费看 | 国产精品久久久久久久久久三级 | 香蕉视频在线播放 | 国产精彩视频一区 | 精品乱码一区二区三四区 | 亚洲人在线播放 | 又爽又黄axxx片免费观看 | 亚洲在线中文字幕 | 一区不卡在线观看 | 91资源在线 | 天天操网 | 国产精品视频在线播放 | 福利在线看 | 看片91| 天堂中文资源在线 | 天堂影院av | 日韩视频在线免费观看 | 一区二区三区免费 | 久久国产一区二区三区 | 国产精品178页 | 国产精品久久久久久网站 | 日韩精品中文字幕在线 | 国产欧美一区二区三区在线看 | 久久精品| 久久大 | 中文字幕成人网 | 久久青草av | 久久久91精品国产一区二区精品 | 国产成人精品一区二区三 | a天堂在线 | 亚洲免费一 | 色综合av | 免费观看的av毛片的网站 | 不卡的av一区 | 国产视频精品区 | 亚洲一av| 精品福利在线视频 | 久色激情| 日韩精品在线视频免费观看 | 久久久久久国 | 久草免费在线视频 |