久久久久久久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'>

                            主站蜘蛛池模板: 91精品久久久久久久 | 亚洲一区视频在线 | 国产丝袜一区二区三区免费视频 | 国产精品中文字幕在线播放 | 91精品久久久久久久久久小网站 | 亚洲一区二区中文字幕 | av天天澡天天爽天天av | 国产精品久久九九 | 久久国产亚洲 | 伊人在线 | 国产在线视频一区二区 | 国产精品久久久久久吹潮 | 97狠狠干| 亚洲欧美日韩精品久久亚洲区 | 欧美一区二区免费在线 | 国产91精品久久久久久久网曝门 | 91中文字幕在线 | 国产三级日本三级 | 国产剧情一区二区三区 | 97色在线视频 | 精品日韩一区 | 色呦呦在线 | 91精品国产色综合久久不卡98口 | 国产精品区二区三区日本 | 国产欧美日韩精品一区 | 欧美日韩久久久 | 日韩一区二区精品 | 丁香六月激情 | 国产精品久久久久久久久久妇女 | 偷拍亚洲色图 | 成人网在线观看 | 日本不卡免费新一二三区 | 毛片国产 | 亚洲精品久久久蜜桃网站 | 国产一区二区在线播放 | 久久乐国产精品 | 亚洲成人久久久 | 亚洲欧美精品国产一级在线 | 国产精品久久在线 | 成人免费精品视频 | 欧美一区二区另类 |