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

        為什么缺少注釋不會在運行時導(dǎo)致 ClassNotFoundEx

        Why doesn#39;t a missing annotation cause a ClassNotFoundException at runtime?(為什么缺少注釋不會在運行時導(dǎo)致 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>

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

                  問題描述

                  考慮以下代碼:

                  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()));
                          }
                  }
                  

                  編譯和運行按預(yù)期工作:

                  Compiling and running works as expected:

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

                  但是再考慮一下:

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

                  我預(yù)計它會拋出 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 之類的東西似乎很方便(無論如何,它似乎應(yīng)該是 @Retention(CLASS) ),但對于許多其他注釋似乎它可能會導(dǎo)致運行時發(fā)生各種不好的事情.

                  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(注解)的早期公共草案中,討論了編譯器和運行時是否應(yīng)該忽略未知注解,以提供更松散的耦合注釋的使用和聲明.一個具體的例子是在 EJB 上使用應(yīng)用程序服務(wù)器特定的注釋來控制部署配置.如果同一個 bean 應(yīng)該部署在不同的應(yīng)用服務(wù)器上,如果運行時簡單地忽略未知注解而不是引發(fā) 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.

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

                  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 的第一個版本沒有正確實現(xiàn)這一點,但在 1.5.0_06 中已修復(fù).你可以在bug數(shù)據(jù)庫中找到相關(guān)的bug6322301,但是沒有指向任何規(guī)范,除了聲稱根據(jù) JSR-175 規(guī)范指南,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".

                  這篇關(guān)于為什么缺少注釋不會在運行時導(dǎo)致 ClassNotFoundException?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  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 操作數(shù)的三元表達(dá)式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲出現(xiàn)的每個字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉(zhuǎn)換 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. 主站蜘蛛池模板: 精品永久| 国产福利小视频 | 成人精品久久 | 亚洲欧美精品 | 91麻豆精品国产91久久久久久 | 国产一区二区影院 | 久久国产精品一区 | 美女拍拍拍网站 | 日韩欧美三级电影在线观看 | 日韩欧美在线一区 | 最新av在线网址 | 91视频免费黄 | 欧美一区二区在线看 | 爱草视频 | 国产精品亚洲精品日韩已方 | 91久久精品一区二区三区 | 亚洲视频精品 | 少妇精品久久久久久久久久 | 成人在线精品视频 | 精品免费国产一区二区三区 | 亚洲天堂av在线 | 日本五月婷婷 | 激情欧美一区二区三区中文字幕 | 中文字幕在线观看一区 | 91久久电影 | 国产精品久久久久9999鸭 | 亚洲啪啪一区 | 中文字幕在线一区 | 日本黄色大片免费 | 最新日韩在线视频 | 精品国产一区二区三区久久 | 亚洲另类自拍 | 国户精品久久久久久久久久久不卡 | 久久亚洲欧美日韩精品专区 | 精品国产18久久久久久二百 | 成人自拍av| 亚洲精品电影网在线观看 | 成人久久18免费网站图片 | 午夜在线免费观看视频 | 中文视频在线 | 免费的一级视频 |