【问题标题】:Why type annotation is not directly supported by java 8 compiler or Eclipse为什么 java 8 编译器或 Eclipse 不直接支持类型注释
【发布时间】:2016-09-21 07:29:46
【问题描述】:

目前正在研究Java8的新特性:http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html

从上面的链接可以清楚地证明:

Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.

但是当我尝试在Eclipse Neon 中添加@NotNull@Readonly 等类型注解时,它根本无法识别这些注解!这太令人沮丧了。

我错过了什么吗?或者如果我需要做更多的配置,比如添加额外的 jar,为什么这仍然被列为 Java 8 的新特性?

【问题讨论】:

  • 你的eclipse中配置java8了吗?
  • 我想是的,因为我的代码包含很多 lambda 表达式,而且它们无论如何都被接受了
  • 认为这还不够。你应该知道的
  • 其实我也不知道为什么
  • 请添加您项目的屏幕显示

标签: java java-8 type-annotation


【解决方案1】:

@Jens 谢谢 :) 我再次从 Google 搜索并找到以下链接: https://docs.oracle.com/javase/tutorial/java/annotations/type_annotations.html

在链接页面中,被告知The Java SE 8 release does not provide a type checking framework, but it allows you to write (or download) a type checking framework that is implemented as one or more pluggable modules that are used in conjunction with the Java compiler.

所以关键是拥有一个checker framework DIY 或使用现有的checker framework。在链接页面的末尾,还有一个现有的Checker Framework - https://checkerframework.org/ 的链接页面,这可能是迄今为止我们可以使用的最好的框架:)

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 2014-09-16
    • 1970-01-01
    • 2018-12-02
    • 2014-12-05
    • 2021-07-06
    • 1970-01-01
    相关资源
    最近更新 更多