JSR 305的状态如何?

我已经看到了问题 JSR305与 JSR308(Java 类型注释)——哪个将成为标准?和我理解之间的区别 JSR 308JSR 305

我还了解到,目前308是为 Java7设计的,而305不是,我对305的整体状态很好奇。

具体来说,我正在我的一些项目中使用 谷歌收藏JSR-305(类似于 Guice 最佳实践倡导者之一) ,我想知道是否有一个更“未来方向”友好的方法,我应该使用。我也计划在 JSR-305小组中询问这个问题,但是那个小组没有太多活动,我只是想知道这里是否有人有更多的信息。

49978 次浏览

According to Alex Millers Java 7 blog, JSR-308 (and 305) are scheduled to go in to Java 7. Perhaps he will show up here and give you more information.

As described in this answer, JSR-305 proposes new annotations such as @NonNull, while JSR-308 proposes allowing annotations in new places such as on generic declarations.

Quoting JSR 308 page:

…this document does not propose any annotations, merely specifying where they can appear in Java code.

JSR 308 (annotations in new places) is included in java 8 under JEP 104.

As of 2017, JSR 305 (new annotations) continues to carry official status of “Dormant”. A question about it's status in the google group has been unanswered since 2010.

There is a reference implementation of the JSR-305 annotations here which is used by many projects, including guava. With maven you can use the JSR-305 reference implementation by adding this to your pom:

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>

JSR 305 will not be part of Java 8:

Java 8 is described by JSR 337: the specification has reached Final status: see here.

  • JSR 308 is definitely in
  • JSR 305 is definitely out

If you are concerned about nullability annotations then I would recommend using the ones provided by SpotBugs project from the edu.umd.cs.findbugs.annotations namespace. These days it should be supported by most linters or IDEs. It's not as nice as proposed javax.annotation in JSR 305, but remember that JSR 305 was never approved and actually no jar file with classes was ever attached to JSR 305 proposal.

Few more interesting articles regarding this:

JSR 305 vs JSR 308

There is barely any relation between JSR 305 and JSR 308. JSR 308 is about ability to apply annotations to generics (java type arguments). JSR 308 has been incorporated as part of Java SE 8.

The only link is that both JSRs are related to a two distinct projects (FindBugs and Checker Framework) which are touching null-safety and nullability annotations topic.

By content the JSRs are no way related.