Overriding Abstract Methods from Multiple Interfaces, Revisited – Functional-Style Programming

Overriding Abstract Methods from Multiple Interfaces, Revisited A general discussion on overriding abstract methods from multiple superinterfaces can be found in §11.12, p. 621. In general, an interface can inherit multiple abstract methods from its superinterfaces, but a functional interface can only have a single abstract method. Note that superinterfaces need not be functional interfaces. … Read moreOverriding Abstract Methods from Multiple Interfaces, Revisited – Functional-Style Programming

Static Method References – Functional-Style Programming

Static Method References Sometimes the lambda body of a lambda expression is just a call to a static method. The lambda expression at (1a) calls the static method now() in the class java.time.LocalDate to obtain the current date from the system clock. Click here to view code image Supplier<LocalDate> dateNowLE = () -> LocalDate.now();  // … Read moreStatic Method References – Functional-Style Programming

Bounded Instance Method References – Functional-Style Programming

Bounded Instance Method References When the body of a lambda expression is a call to an instance method, the method reference specified depends on whether the object on which the instance method is invoked exists or not at the time the method reference is defined. In the code below, the reference sb is declared and … Read moreBounded Instance Method References – Functional-Style Programming

Unbounded Instance Method References – Functional-Style Programming

Unbounded Instance Method References In the case of an unbounded instance method reference, the target reference is determined when the method reference is executed, as it is the first argument passed to the method reference. This is embodied in the following rule: A lambda expression of the form Click here to view code image (arg0, … Read moreUnbounded Instance Method References – Functional-Style Programming

Method and Constructor References – Functional-Style Programming

13.13 Method and Constructor References So far we have seen that a Java program can use primitive values, objects (including arrays), and lambda expressions. In this section, we introduce the fourth kind of value that a Java program can use, called method references (and their specializations to constructors and array construction). As we shall see, … Read moreMethod and Constructor References – Functional-Style Programming

Composing Two-Arity Functions – Functional-Style Programming

Composing Two-Arity Functions The interface BiFunction<T, U, R> provides the andThen() method for creating compound two-arity functions. Given a two-arity function f and a one-arity function g, the method evaluates the functions as follows: f.andThen(g).apply(x, y) emulates g.apply(f.apply(x, y))—that is, the two-arity function f is executed first and the one-arity function g last. In the … Read moreComposing Two-Arity Functions – Functional-Style Programming

Selected Interfaces in the Java SE Platform API – Functional-Style Programming

Selected Interfaces in the Java SE Platform API A functional interface, like any other interface, can always be implemented by a class. The @FunctionalInterface annotation on a functional interface in the Java SE Platform API documentation indicates that the implementation of the functional interface is meant to be implemented by lambda expressions. In the Java … Read moreSelected Interfaces in the Java SE Platform API – Functional-Style Programming

Lambda Expressions – Functional-Style Programming

13.2 Lambda Expressions Lambda expressions implement functional interfaces, and thereby define anonymous functions—that is, functions that do not have a name. They can be used as a value in a program, without the excess baggage of first being packaged into objects. As we shall see, these two features together facilitate behavior parameterization— that is, customizing … Read moreLambda Expressions – Functional-Style Programming

Accessing Members in an Enclosing Class – Functional-Style Programming

Accessing Members in an Enclosing Class Just like nested blocks, a lambda expression has lexical or block scope—that is, names used in a lambda expression are resolved lexically in the local context in which the lambda expression is defined. A lambda expression does not inherit names of members declared in the functional interface it implements, … Read moreAccessing Members in an Enclosing Class – Functional-Style Programming

Lambda Body – Functional-Style Programming

Lambda Body A lambda body is either a single expression or a statement block. Execution of a lambda body either has a non-void return (i.e., its evaluation returns a value), or has a void return (i.e., its evaluation does not return a value), or its evaluation throws an exception. A single-expression lambda body is used … Read moreLambda Body – Functional-Style Programming