Java 8, Type Annotations and JSR 308

前端 未结 2 1753
醉梦人生
醉梦人生 2021-01-02 02:35

I\'ve installed the last JDK 8 (b116) but I noticed that I can\'t use type annotations. For example reading the Java tutorial if I write:

String str = null;
         


        
相关标签:
2条回答
  • 2021-01-02 02:48

    For the second part:

    I also don't understand if the annotations like: NonNull, Interned, etc. will be inserted in the JDK or if we have to download the Checker Framework.

    The Oracle-distributed JDK does not contain annotations like @NonNull and @Interned -- neither definitions of them, nor occurrences of them on JDK methods.

    However, the Checker Framework contains annotated versions of the JDK, as explained in the Checker Framework manual. The Checker Framework lets you use the definitive version of a library at run time and even at compile time, while pluggable type-checking sees the annotations and thus the type-checking results are more precise.

    0 讨论(0)
  • 2021-01-02 03:12

    You have answered the first part of your Question yourself.

    For the second part:

    I also don't understand if the annotations like: NonNull, Interned, etc. will be inserted in the JDK or if we have to download the Checker Framework.

    Annotations are just a kind of Java class / interface. They have to be defined in source code and compiled.

    Ideally you should the definitive source code and / or bytecode files, obtained from the canonical place. However, if you were to reproduce the salient parts of the annotations' source code (the package name, annotation name, field names and type) and compile it, the rest of the JVM would be none the wiser.

    But when you talk about specific annotations like @NonNull and @Interned, you need to realize that there could exist multiple versions of these in different packages. This could cause issues (for annotation processing software) until standard / defacto standard versions emerge. I don't know if the Checkers Framework could be called a defacto standard ... yet.

    You asked if the checkers annotations would be added to the Java 8 library. I personally doubt it, because the package name for those annotations would be unacceptable. But wait and see ...

    0 讨论(0)
提交回复
热议问题