如何为@since标签扫描Java标准API的所有Javadocs?

发布于 2025-02-03 17:20:18 字数 443 浏览 3 评论 0 原文

我想为标准Java API中存在的类,其方法和枚举值绘制出Java版本,因为这些版本。例如,自Java 1.0和 String :: strip()方法以来,标准类字符串自Java 11以来存在。类和该方法都具有@由于在其Javadocs中使用适当的Java版本标记,这就是我要编程扫描的标签。

也许还有另一种方式,与Javadoc无关?例如,由于Java 9,编译器支持 -Release 参数,除其他外,还可以检查使用的API与所选版本的Java版本的兼容性。如果是 -Release 10 和带有 String :: strip :: strip()的代码>汇编错误。编译器如何做?它是在每次汇编过程中扫描 src.zip javadocs还是使用更智能的技术?

I want to make a map of Java versions to classes, their methods and enum values that exist in the standard Java API since those versions. For example the standard class String exists since Java 1.0 and the String::strip() method exists since Java 11. Both the class and the method have the @since tag with the appropriate Java version in their javadocs and this is what I want to scan programmatically.

Maybe there is another way, not related to javadoc? For example since Java 9 the compiler supports the -release argument that among other things checks the compatibility of the used APIs with the chosen version of Java release. In case of -release 10 and a code with String::strip() a compilation error is thrown. How does the compiler do it? Does it scan the src.zip for javadocs during every compilation or use a smarter technique?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃颗糖壮壮胆 2025-02-10 17:20:18

解析 @since 可能是错误的,因为有一些陷阱:

  • 尤其是对于方法,它是不一致的;例如, string.startswith(string) @since 1.0 没有 @since 标记
  • 该值可能是意外的,请参见 JDK-8254572
  • 可能是不正确的。该值均未以任何方式验证,因此可能发生不正确的情况,示例为: JDK-6372816

href =“ https://bugs.openjdk.java.java.net/browse/jdk-8260561” rel =“ nofollow noreferrer”> jdk 可以查看“ nofollow noreferrer”>“新” tab 该文档的在Java 17中添加 jdk-8265055 (这是基于 @since 信息)。

- 版本 javac 的选项使用jdk安装中的文件 lib/ct.sym ,它存储了先前版本的公共API的信息。请参阅

但是,有第三方工具可让您生成或比较Java API签名:

Parsing @since might be error-prone because there are some pitfalls:

If you as developer just want to know which new API was added, you can have a look at the "New" tab of the documentation, added in Java 17 by JDK-8265055 (this is based on the @since information).

The --release option of javac uses the file lib/ct.sym from the JDK installation which stores information about the public API of previous versions. See the "Implementation" section of JEP 247. There are however some pitfalls with this as well:

  • The support for older versions is dropped; for example Java 12 and newer does not support Java 6
  • At the moment it does not include information about unsupported API; most prominently sun.misc.Unsafe

There are however third-party tools which allow you to generate or compare the Java API signatures:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文