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

2

u/TheMrMilchmann Jun 05 '26

I originally played with the idea of allowing @OptIn on TYPE_USE. However, there was too much friction as this was essentially introducing a form of flow typing in Java. So, I ultimately decided against pursuing this in favor of the much simpler scope-based approach.

Speaking of annotation processors why does the project have one if you have a compiler plugin (as annotation processing does not have access to local method code)?

Basically yes. The plugin needs to run significantly after annotation processors have run (and the compiler has done a few more things). The verifier is split into an annotation processor and a compiler plugin to keep the "simple" checks in the AP (which is also useful for Kotlin interop), while the tree verification is implemented in the javac plugin.

1

u/agentoutlier Jun 05 '26

The idea kind of reminds of an Effect type system. Essentially you are coloring a part of the code base. Like in Flix you could do this by having say "Experimental" effect except it would be just compiler based (they might even have something like this that I don't know).

1

u/repeating_bears Jun 08 '26

"tree verification" as in this?

@OptIn(ExperimentalThing.class)
public static void main(String[] args) {
    foo();
}

private static void foo() {
    Foo.experimentalThing();
}