Locally enabled preview features

Chen Liang chen.l.liang at oracle.com
Tue Jul 8 14:03:58 UTC 2025


I think there are something related to your problem - the multi-release jars do attempt to increase integration with different feature sets, and in fact, JLS requires class files that is compiled with --enable-preview but did not make use of any preview features to have their minor version set to 0. So to control the scope, I think either using multiple compilation (multiple source sets) or checking the minor version in class files to determine the scope works.

As to your proposal - you see others have already listed a few arguments against it, and it is not the only way to address your problem. I hope the two existing solutions I listed above can somewhat alleviate the problem you face.

Regards,
Chen
________________________________
From: amber-dev <amber-dev-retn at openjdk.org> on behalf of Goldmensch <pm at goldmensch.dev>
Sent: Monday, July 7, 2025 10:30 PM
To: amber-dev at openjdk.org <amber-dev at openjdk.org>
Subject: Locally enabled preview features

Hi folks!
I’m wondering if the idea of “locally” enabled preview features came up yet. It would make it possible to enable certain preview features for a class, package or module by annotating it for example. Doing so would allow to use preview features much easier in production to test them, while keeping the usage “scope” small so that changes can be easily integrated without risking the integrity of the codebase. Of course some feature like virtual threads (by the time they were in preview) could not be enabled in such way due to the consequences to “non preview enabled code” but flexible constructor bodies, module import declarations, perhaps even scoped values and much more could be.

Was this idea ever considered yet and if yes, what are the points against it?

Best regards,
Nick Hensel


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20250708/38065196/attachment.htm>


More information about the amber-dev mailing list