久久久久久久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 尋找具有特定注解的方法及其注解元素的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  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.

                  這篇關于Java 尋找具有特定注解的方法及其注解元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 原語?)
                  <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'>

                            主站蜘蛛池模板: 日韩高清中文字幕 | 国产精品一区二区免费 | 成人性生交大片免费看r链接 | 日本成年免费网站 | 国产精品久久av | 天堂资源 | 国产成人av在线 | 华人黄网站大全 | 日韩在线免费 | 网站黄色av| 亚洲综合网站 | 一级片在线观看视频 | 亚洲一区二区三区在线视频 | 久久99精品久久久久婷婷 | 免费看色 | 日朝毛片 | 日韩精品免费播放 | 中文字幕精品一区二区三区精品 | 99精品网 | 国产精品免费看 | 麻豆国产一区二区三区四区 | 91精品久久久 | 91久久久久久久久久久 | 国产精品亚洲成在人线 | 亚洲国产日韩欧美 | 久久蜜桃av一区二区天堂 | 中文视频在线 | 精品久久香蕉国产线看观看亚洲 | 美女天天操 | 日韩1区 | 热re99久久精品国99热观看 | 成人在线免费电影 | 粉嫩av久久一区二区三区 | 福利一区在线观看 | 中文字幕不卡视频在线观看 | 欧美日韩在线电影 | 色毛片| 欧美成人猛片aaaaaaa | 日韩1区| 在线播放亚洲 | 人人看人人搞 |