Preview APIs for preview features -- JDK 14+

Gunnar Morling gunnar at hibernate.org
Wed Aug 7 11:00:50 UTC 2019


Hi all,

> Joe Darcy has proposed that associated APIs are annotated explicitly
> (e.g. @java.lang.annotation.PreviewFeature) so that their use can be
> detected at compile time.

I think that's a very useful addition.

IIUC, this is only geared towards usage within the JDK APIs themselves;
maybe it could be considered to widen the scope of the proposal and enable
usage of this functionality by 3rd party APIs? Specifically, I'm thinking
of supporting similar, already existing annotations, e.g. @Beta in Guava or
or @Incubating in Hibernate. So for that it'd help if:

* it were configurable which annotation(s) are used as the preview API
marker(s)
* it were possible to distinguish between opting into using preview
*language features* and preview *APIs*. Oftentimes, one might be more
willing to accept the potential risks associated to using the latter as
than to using the former.

Currently, specific tooling is needed to check for usage of APIs marked
with such annotations (e.g. there's an ErrorProne plug-in for @Beta), but
unlike a compiler option which *prevents* usage of preview APIs by default,
this tooling must be explicitly set up as part of the compilation,
*allowing* their usage by default. Hence I think it'd be great to have
support for this by the compiler itself.

Any thoughts?

Thanks,

--Gunnar


More information about the jdk-dev mailing list