r/java • • Jun 05 '26

Introducing opt-in requirements for Java APIs

https://osmerion.github.io/OptIn/blog/welcome
49 Upvotes

27 comments sorted by

View all comments

Show parent comment

4

u/TheMrMilchmann Jun 05 '26

Do you need to configure javac, or does just adding the library run the relevant (I assume) annotation processor?

There is actually quite a bit of javac configuration required because the verification partly happens in an annotation processor and partly in a javac plugin. It's documented here.

I strongly recommend using the Gradle plugin and (in the future) the Maven plugin which will to the work for you.

Also, why the extra step of requiring users to provide their own annotation, which itself gets annotated with the @OptInRequired annotation?

There can be multiple different opt-in requirements and you might not want to opt into all of them. The approach leaves the decision to library authors. For example, one might have a UI library with an @ExperimentalTableApi and an @ExperimentalWebViewApi.