r/java • • Jun 05 '26

Introducing opt-in requirements for Java APIs

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

27 comments sorted by

View all comments

Show parent comment

12

u/repeating_bears Jun 05 '26

You need something to say what you're opting into.

@OptIn(towhat)

Declaring the annotation is the library author's way to declare the what.

Without that, you only have the granularity of the library saying "it's experimental" and the user saying "I accept everything experimental from every library".

2

u/aboothe726 Jun 05 '26 edited Jun 05 '26

Appreciate the response!

What you're describing might be fine, especially for internal libraries. Many is the time that I've put an experiment into code at work, looked away for a minute, and suddenly there are 2 or 3 users of the code despite comments and @Deprecated. It's possible that Maven Enforcer Plugin or ArchUnit could have helped, but those come with their own issues.

Also, in my mind, I'm also imagining that you could use a string as the category and/or message within a fixed annotation.

Certainly not trying to tell anyone how to write or use the library. Just sharing my thoughts, for whatever that's worth.

Thank you for sharing!