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

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

Overview of Built-In Functional Interfaces – Functional-Style Programming

13.4 Overview of Built-In Functional Interfaces Earlier in this chapter, specialized interfaces (including some functional ones) were mentioned that are readily available in the Java SE Platform API (p. 678). To facilitate defining common functions with lambda expressions, the Java SE Platform API also provides a versatile set of functional interfaces for this purpose. The … Read moreOverview of Built-In Functional Interfaces – Functional-Style Programming

Predicates – Functional-Style Programming

13.6 Predicates The Predicate<T> interface should be familiar by now, having been used earlier in Example 13.1, Example 13.2, and Example 13.3. The Predicate<T> interface defines a boolean-valued function in terms of an instance of its type parameter T. From Table 13.5, we see that its functional method test() has the type T -> boolean—that … Read morePredicates – Functional-Style Programming

Primitive Type Specializations of BinaryOperator – Functional-Style Programming

Primitive Type Specializations of BinaryOperator<T> Table 13.10 shows that the BinaryOperator<T> interface has three primitive type specializations to int, long, and double. The specializations are named PrimBinaryOperator, where Prim is either an Int, Long, or Double (Table 13.10). These primitive type binary operators have the functional method applyAsPrim: (primitive, primitive) -> primitive, where primitive is … Read morePrimitive Type Specializations of BinaryOperator – Functional-Style Programming

Composing Predicates – Functional-Style Programming

Composing Predicates The predicate interfaces define default methods to compose compound predicates—that is, to chain together predicates with logical AND and OR operations. Click here to view code image default Predicate<T> negate() Returns a predicate that represents the logical negation of this predicate. Click here to view code image default Predicate<T> and(Predicate<? super T> other) … Read moreComposing Predicates – Functional-Style Programming