Javadoc (b116) lacks @FunctionalInterface on Observer signature
zhong.j.yu at gmail.com
Fri Nov 22 12:49:16 PST 2013
On Fri, Nov 22, 2013 at 12:39 PM, Paul Benedict <pbenedict at apache.org> wrote:
> The design intent is important to me. I want the compiler to enforce the
> intent with @FunctionalInterface. Zhong, where you get compiler errors is
> project specific. Not all consuming code is in the same project. The errors
> may not show up until the client uses the upgraded jar.
In the long history of Java, are there anecdotes that a new method is
accidentally added to a public interface? Has the experience shown
that it is worthy of a prevention mechanism (which is far from free)?
> But I am not sure this thread should be hijacked with that concern. I'd like
No hijacking. The center issue here is what @FunctionalInterface is
intended for. The discussion goes no where if we are not clear about
> to keep the discussion on simply enhancing the javadocs to call out the
> implicitness of some functional interfaces. I think the word "implicit"
> should be used, with perhaps a warning that no intent exists it will remain
> a functional interface.
A functional interface is a functional interface. A public one will
remain a functional interface till the end of time. If unforeseeable
things happen that break that assumption, the marking of
@FunctionalInterface will not make any difference.
The concept of "functional interface" is only to serve lambda
expressions and method references. That's at use-site, not declaration
site of interfaces. There's no reason to say that a Closeable could
not be used as a method parameter type, and the argument could not be
a lambda expression. There's no reason to say that a Consumer<T> could
not be used as a non-functional interface could be used typically.
@FunctionalInterface on an interface does not convey anything that
users should adhere to.
> On Fri, Nov 22, 2013 at 12:09 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
>> The chance seems very small that one could accidentally add an
>> abstract method to an interface (without being hit by lots of
>> compilation errors else where).
>> On Fri, Nov 22, 2013 at 11:52 AM, Brian Goetz <brian.goetz at oracle.com>
>> >> I still have no idea how the annotation is supposed to help us. Can
>> >> anyone provide a concrete use case for @FunctionalInterface?
>> > It captures design intent; the compiler assists you by enforcing that
>> > design
>> > intent (erroring if the class has more than one abstract method.) Like
>> > the
>> > @Override annotation.
More information about the lambda-dev