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

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

  • <small id='pQlPS'></small><noframes id='pQlPS'>

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

        為什么缺少注釋不會在運行時導致 ClassNotFoundEx

        Why doesn#39;t a missing annotation cause a ClassNotFoundException at runtime?(為什么缺少注釋不會在運行時導致 ClassNotFoundException?)
        <i id='qiMRd'><tr id='qiMRd'><dt id='qiMRd'><q id='qiMRd'><span id='qiMRd'><b id='qiMRd'><form id='qiMRd'><ins id='qiMRd'></ins><ul id='qiMRd'></ul><sub id='qiMRd'></sub></form><legend id='qiMRd'></legend><bdo id='qiMRd'><pre id='qiMRd'><center id='qiMRd'></center></pre></bdo></b><th id='qiMRd'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qiMRd'><tfoot id='qiMRd'></tfoot><dl id='qiMRd'><fieldset id='qiMRd'></fieldset></dl></div>

          <tbody id='qiMRd'></tbody>

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

            1. <tfoot id='qiMRd'></tfoot>
            2. <legend id='qiMRd'><style id='qiMRd'><dir id='qiMRd'><q id='qiMRd'></q></dir></style></legend>
                <bdo id='qiMRd'></bdo><ul id='qiMRd'></ul>

                  本文介紹了為什么缺少注釋不會在運行時導致 ClassNotFoundException?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  考慮以下代碼:

                  A.java:

                  import java.lang.annotation.Retention;
                  import java.lang.annotation.RetentionPolicy;
                  
                  @Retention(RetentionPolicy.RUNTIME)
                  @interface A{}
                  

                  C.java:

                  import java.util.*;
                  
                  @A public class C {
                          public static void main(String[] args){
                                  System.out.println(Arrays.toString(C.class.getAnnotations()));
                          }
                  }
                  

                  編譯和運行按預期工作:

                  Compiling and running works as expected:

                  $ javac *.java
                  $ java -cp . C
                  [@A()]
                  

                  但是再考慮一下:

                  $ rm A.class
                  $ java -cp . C
                  []
                  

                  我預計它會拋出 ClassNotFoundException,因為缺少 @A.但相反,它會默默地刪除注釋.

                  I would've expected it to throw a ClassNotFoundException, since @A is missing. But instead, it silently drops the annotation.

                  這種行為是否記錄在 JLS 中的某個地方,還是 Sun 的 JVM 的怪癖?這樣做的理由是什么?

                  Is this behaviour documented in the JLS somewhere, or is it a quirk of Sun's JVM? What's the rationale for it?

                  對于 javax.annotation.Nonnull 之類的東西似乎很方便(無論如何,它似乎應該是 @Retention(CLASS) ),但對于許多其他注釋似乎它可能會導致運行時發生各種不好的事情.

                  It seems convenient for things like javax.annotation.Nonnull (which seems like it should've been @Retention(CLASS) anyway), but for many other annotations it seems like it could cause various bad things to happen at runtime.

                  推薦答案

                  在 JSR-175(注解)的早期公共草案中,討論了編譯器和運行時是否應該忽略未知注解,以提供更松散的耦合注釋的使用和聲明.一個具體的例子是在 EJB 上使用應用程序服務器特定的注釋來控制部署配置.如果同一個 bean 應該部署在不同的應用服務器上,如果運行時簡單地忽略未知注解而不是引發 NoClassDefFoundError 會很方便.

                  In the earlier public drafts for JSR-175 (annotations), it was discussed if the compiler and runtime should ignore unknown annotations, to provide a looser coupling between the usage and declaration of annotations. A specific example was the use of applications server specific annotations on an EJB to control the deployment configuration. If the same bean should be deployed on a different application server, it would have been convenient if the runtime simply ignored the unknown annotations instead of raising a NoClassDefFoundError.

                  即使措辭有點模糊,我認為您看到的行為在 JLS 13.5.7: "... 刪除注釋對 Java 中程序的二進制表示的正確鏈接沒有影響編程語言."我將此解釋為好像注釋已刪除(在運行時不可用),程序仍應鏈接并運行,這意味著在通過反射訪問時會簡單地忽略未知注釋.

                  Even if the wording is a little bit vague, I assume that the behaviour you are seeing is specified in JLS 13.5.7: "... removing annotations has no effect on the correct linkage of the binary representations of programs in the Java programming language." I interpret this as if annotations are removed (not available at runtime), the program should still link and run and that this implies that the unknown annotations are simply ignored when accessed through reflection.

                  Sun 的 JDK 5 的第一個版本沒有正確實現這一點,但在 1.5.0_06 中已修復.你可以在bug數據庫中找到相關的bug6322301,但是沒有指向任何規范,除了聲稱根據 JSR-175 規范指南,getAnnotations 必須忽略未知注釋".

                  The first release of Sun's JDK 5 did not implement this correctly, but it was fixed in 1.5.0_06. You can find the relevant bug 6322301 in the bug database, but it does not point to any specifications except claiming that "according to the JSR-175 spec lead, unknown annotations must be ignored by getAnnotations".

                  這篇關于為什么缺少注釋不會在運行時導致 ClassNotFoundException?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 原語?)
                      <tbody id='De13b'></tbody>
                    <legend id='De13b'><style id='De13b'><dir id='De13b'><q id='De13b'></q></dir></style></legend>
                        <bdo id='De13b'></bdo><ul id='De13b'></ul>

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

                          2. 主站蜘蛛池模板: 亚洲天堂网址 | 婷婷激情综合网 | 午夜视频在线看 | 亚洲欧美日韩一区 | 老司机午夜免费精品视频 | 中文字幕日韩在线观看 | 国产一级片在线播放 | 亚洲激情一区二区 | 日日夜夜操操 | 国产精品久久免费 | 亚洲日本高清 | 国产色视频一区二区三区qq号 | 午夜国产 | 日本久久精品视频 | 天天射天天干天天操 | 国产在线日韩 | 久久r | 亚洲福利网站 | 色网站女女 | 久久久久久黄色 | 久久久综合网 | 国产精品一级二级 | 中文字幕国产视频 | 婷婷午夜天 | 91久久国产综合久久91精品网站 | 日本在线免费 | 五月婷婷激情综合 | 成人精品影院 | 日本免费黄色网址 | 爱搞逼综合网 | www.97超碰| 啊v在线观看 | 欧美成人性生活视频 | 深夜福利网站 | 久久精品国产亚洲 | 天堂影院av | 国产成人一区二区三区 | 草草在线视频 | 亚洲一区二区三区在线 | 午夜精品视频在线观看 | 国产综合久久 |