JSR305 与 JSR308(Java 类型注释)- 哪个将成为标准?
似乎有两个不同的 JSR 用于注释。
JSR-305:软件缺陷检测注释 (其他资源)
JSR-308:Java 类型注释 < a href="https://checkerframework.org/jsr308/" rel="nofollow noreferrer">(附加资源)
两者似乎都面向静态代码分析。
您知道吗:
- Java SE 7 或 Java EE 6 中哪一个会出现?
- 每个 JSR 的“稳定性”如何?
- 其中一个是否取代(或废弃)另一个?
There seem to be two different JSRs for annotations.
JSR-305: Annotations for Software Defect Detection (additional resource)
JSR-308: Annotations on Java Types (additional resource)
Both seem to be oriented towards static code analysis.
Do you know:
- which of the both is going to be either in Java SE 7 or Java EE 6?
- how "stable" is each JSR?
- does the one supersedes (or obsoletes) the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以回答你的最后一个问题。它们不是同一件事。 305 是关于您已经可以放置它们的新注释,这可以帮助为合同系统设计提供编程可见性。因此,如果某个方法应该不返回 null,或者如果某个方法应该永远不会接收 null 参数,则可以告诉分析注释的系统在这段代码中查找这种特定情况。
308 是为了能够注释更多的东西,例如泛型参数和类型转换。我想它的主要用途是能够抑制特定类型转换的警告,而不必为此目的声明局部变量。 @SuppressWarnings 注释已经存在(而 JSR-305 会定义新的注释),但在 JSR-308 中它可以应用于更多情况。
据 this 308 将成为 Java7 的一部分,这意味着它非常稳定。 JSR-305 不在列表中,因此看起来它不会进入 Java7。
I can answer your last question. They are not the same thing. 305 is about new annotations where you can already put them, which can help provide programmatic visibility into a design by contract system. So that if a certain method is supposed to not return null, or if a certain method is supposed to never receive a null parameter, it is possible to tell the system analyzing the annotations to look out for this specific case at this piece of code.
308 is about being able to annotate more things, such as a generic parameter and a type cast. I imagine a primary use for that is to be able to suppress warning on a specific type cast, instead of having to declare a local variable for that purpose. The @SuppressWarnings annotation already exists (whereas JSR-305 would look to define new ones), but in JSR-308 it could be applied to more cases.
According to this 308 will be part of Java7, which would imply it is quite well along to being stable. JSR-305 isn't on the list, so it doesn't look like it will make it to Java7.
根据该文档,最后更新于 2010-09-19,JSR 308 是
“推迟到 JDK 8 或更高版本”:
http://openjdk.java.net/projects/jdk7/features/
According to this document, last updated on 2010-09-19, JSR 308 is
"Deferred to JDK 8 or later":
http://openjdk.java.net/projects/jdk7/features/
对于未来的读者,JSR 308 正在集成到 Java 7 中。它的一些更改已经推送到 Java 7 的公共测试版中。但是 JSR305 没有成功。
For future readers, JSR 308 is being integrated into Java 7. Some of its changes have already been pushed to the public betas of Java 7. JSR305 however didn't make the cut.