Java的8,类型注解和JSR 308 [英] Java 8, Type Annotations and JSR 308

查看:618
本文介绍了Java的8,类型注解和JSR 308的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了JDK最后8(B116),但我发现我不能使用类型注解。
例如阅读Java教程,如果我写的:

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;
String myString = (@NonNull String) str;

TEST st = new @Interned TEST();

编译器给我以下错误:

the compiler give me the following error:

annotation type not applicable to this kind of declaration

现在,它的作品。使用某一类型的注释之前,我们必须注解注释
@Target(ElementType.TYPE_USE)。看看下面的评论!

Now it works. Before using a type annotations we must annotate the annotation with @Target(ElementType.TYPE_USE). Look at the comments below!

我也不太明白,如果注释,如:非空实习,等会
插在JDK,或者如果我们要下载检查框架

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

推荐答案

您已经回答了你的问题的第一部分你自己。

You have answered the first part of your Question yourself.

有关第二部分:

我也不太明白,如果注释,如:非空实习等将插在在JDK或者如果我们要下载的检查框架。

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.

注解只是一种Java类/接口。他们在源$ C ​​$ C定义和编译。

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

在理想情况下,你应该在的明确的源$ C ​​$ c和/或字节code文件,从规范的地方获得。但是,如果你要复制注释源$ C ​​$ C(包名,注释名,字段名和类型)的突出部分和编译,JVM的其余部分将是毫无收获。

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.

但是,当你谈论具体的注解,比如 @NonNull @Interned ,你需要认识到,有可能存在于不同的包的这些多个版本。这可能会导致问题(注释处理软件),直到标准/事实上的标准版本出现。我不知道,如果跳棋框架可以被称为一个事实上的标准...但。

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.

您问,如果跳棋注释将被添加到Java 8库。我个人对此表示怀疑,因为这些标注包名是不可接受的。但观望...

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

这篇关于Java的8,类型注解和JSR 308的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆