My understanding of https://clojure.atlassian.net/browse/CLJ-2799 is that in clojure 1.12 we'll be able to pass functions in any place where an interface annotated with @FunctionalInterface is expected. But that annotation must be present in the java interface code for it to work.
Is there any particular reason in Java NOT to use that annotation in situations where the intention is to use the things as functions?
I'm trying out https://github.com/openjdk/jextract and it generates code that looks like:
public class wl_notify_func_t {
...
/**
* The function pointer signature, expressed as a functional interface
*/
public interface Function {
void apply(MemorySegment listener, MemorySegment data);
}
It seems intended to be used as a "functional interface" since those words are in the comment, but it lacks the annotation.
What reasons are there in java to add or not add that annotation in Java?FunctionalInterfaces can only have one method, so marking it this way means not changing your mind and adding another method later
but if that is your intent, then no reason not to
Ah, makes sense. I think in java you can use lambdas any time there's a "Single Abstract Method" interface. Do you know offhand if those lambda usages will also break if a method is later added to the interface? I'm thinking they would, and thus if lambda functions are used in docs and such, it strengthens the case for just making the thing a FunctionalInterface?
it depends :)
if they are still distinct by arity then this is not a breaking change
I think! we went through some examples like this but I may be misremembering
Thanks, good to know
actually that may be wrong - I think it would break use of a lambda in that case
...and then default interface methods enter the bar 🙂