久久久久久久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. 主站蜘蛛池模板: 黄色三级在线播放 | 中文字幕一区二区三区日韩精品 | 亚洲一一在线 | 中文字幕一区二区三区不卡在线 | 日本羞羞影院 | 亚洲欧美一区二区三区视频 | 午夜av免费 | 91精品国产综合久久久久久 | 国产精品视频一区二区三区 | 青青草国产在线观看 | 国产毛片毛片 | 国产成人精品午夜 | 国产精品国产亚洲精品看不卡15 | 91麻豆精品国产91久久久久久久久 | 亚洲一区精品在线 | 久久精品一区 | 国产精品自产拍在线观看蜜 | 国产成人福利在线观看 | 91精品国产91久久久久游泳池 | 欧美激情一区二区 | 成人免费视频网站在线看 | 亚洲福利一区二区 | 网站黄色av| 国产三级一区二区 | 99精品免费| 黑人精品欧美一区二区蜜桃 | 久热中文字幕 | 久久久精品 | 在线国产一区 | 日韩中文字幕在线视频 | 久综合| 阿v视频在线观看 | 欧美日韩精品 | 欧美激情第一区 | 日韩久久网 | 97超在线视频| 日韩精品在线一区 | 成人做爰www免费看视频网站 | 中文字幕人成人 | 亚洲国产精品一区 | 伊人精品国产 |