On 27 November 2012 02:12, Mike Duigou <[email protected]> wrote:
> In the original patch which added the basic lambda functional interfaces,
> CR#8001634 [1], none of the interfaces extended other interfaces. The reason
> was primarily that the javac compiler did not, at the time that 8001634 was
> proposed, support extension methods. The compiler now supports adding of
> method defaults so this patch improves the functional interfaces by filing in
> the inheritance hierarchy.
>
> Adding the parent interfaces and default methods allows each functional
> interface to be used in more places. It is especially important for the
> functional interfaces which support primitive types, IntSupplier,
> IntFunction, IntUnaryOperator, IntBinaryOperator, etc. We expect that
> eventually standard implementations of these interfaces will be provided for
> functions like max, min, sum, etc. By extending the reference oriented
> functional interfaces such as Function, the primitive implementations can be
> used with the boxed primitive types along with the primitive types for which
> they are defined.
>
> The patch to add parent interfaces and default methods can be found here:
>
> http://cr.openjdk.java.net/~mduigou/8004015/0/webrev/
> http://cr.openjdk.java.net/~mduigou/8004015/0/specdiff/java/util/function/package-summary.html
Each of the default methods is formatted on a single line. I consider
this to be bad style, they should be formatted as per "normal"
methods:
@Override
public default Double operate(Double left, Double right) {
return operateAsDouble((double) left, (double) right);
}
It is vitally important to get this kind of formatting/style correct.
Developers the world over will be copying what the style is in these
classes.
There is also no Javadoc on the default method override. In this case,
passing a null to either parameter will result in an NPE. This should
be documented.
More generally, you/Oracle should define a standard form of words for
describing what a default method does. Interfaces have not had them
before, and their behaviour needs documenting (even if it seems
obvious).
/**
* An operation upon two operands yielding a result.
* The operands and the result are all of the same type.
* <p>
* The default implementation calls {@link operate(double,double)},
* throwing NullPointerException if either input is null.
*
* @param left the first operand, not null
* @param left the first operand, not null
* @return the result, not null
*/
@Override
public default Double operate(Double left, Double right) {
return operateAsDouble((double) left, (double) right);
}
Stephen