apply (original) (raw)

Remi Forax forax at univ-mlv.fr
Sun Dec 16 14:30:46 PST 2012


On 12/16/2012 11:10 PM, Doug Lea wrote:

(Still in the midst of the painful setup allowing JDK8 j.u.c builds to track lambda-libs...) Could someone please explain clearly and compellingly why we are using different method names for all the functional forms in java.util.function instead of just "apply"?

Problems come when a functional interface inherits from another, because in that case the two methods are considered as overloads and Java has specific rules for overloads like a method with the same parameters can't have different return type. by example, if Supplier use apply, IntSupplier can not inherits from Supplier.

interface Supplier { T apply(); } interface IntSupplier extends Supplier { int apply(); } // won't compile

and we want InSupplier to inherit from Supplier to avoid function interface to functional interface conversion that currently always creates a new object.

Does anyone think that other users won't find this very annoying?

It's annoying for framework writers not users of those frameworks because writing a lambda doesn't require to know the method name.

-Doug

Rémi



More information about the lambda-libs-spec-experts mailing list