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

                            主站蜘蛛池模板: 天天色天天爱 | 黄色国产片| 日本少妇视频 | 欧美在线一区二区 | 亚洲区在线 | 欧美日韩免费看 | 亚洲亚洲人成综合网络 | 一区二区三区在线观看免费 | 免费看一级毛片 | 国产激情综合五月久久 | 欧美黄色免费网站 | av在线资源 | 精品国产成人 | 狠狠五月天 | 亚洲三级视频 | 免费av片| 黄色高潮视频 | 亚洲性天堂| 国产精品一区在线观看 | 国产xxx| 黄www.| 四虎影院最新网址 | 久久天天 | 日本精品视频在线观看 | 免费一级a毛片 | 日韩黄色在线视频 | 中国一级毛片 | 四川一级毛毛片 | 日本特级黄色片 | 五月久久| 日本黄色一级视频 | 一区二区三区黄色 | 视频爱爱免费视频爱爱太爽 | 最新国产视频 | 天天干天天做 | 欧美特黄一级 | 亚洲黄色天堂 | 久久网av | 中文字幕在线日韩 | 国产草草影院 | 久久国产精品一区二区 |