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?
Parsing @since
might be error-prone because there are some pitfalls:
String.startsWith(String)
has @since 1.0
but String.endsWith(String)
has no @since
tagIf 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:
sun.misc.Unsafe
There are however third-party tools which allow you to generate or compare the Java API signatures: