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

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

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

Lambda Expressions versus Anonymous Classes – Functional-Style Programming

Lambda Expressions versus Anonymous Classes Implementation A lambda expression can only be used to provide implementation of exactly one functional interface. It represents an anonymous function. Unlike an object, it has only behavior and no state. An anonymous class is restricted to either implementing one interface or extending one class, but it is not restricted … Read moreLambda Expressions versus Anonymous Classes – Functional-Style Programming

Primitive Type Specializations of BiFunction – Functional-Style Programming

Primitive Type Specializations of BiFunction<T, U, R> Table 13.8 shows that the BiFunction<T, U, R> interface has three primitive type twoarity generic specializations to int, long, and double, but they do not define any default methods for creating compound functions. The specializations are named ToPrimBiFunction<T, U>, where Prim is either Int, Long, or Double. These … Read morePrimitive Type Specializations of BiFunction – Functional-Style Programming

Primitive Type Specializations of Function – Functional-Style Programming

Primitive Type Specializations of Function<T, R> As can be seen in Table 13.7, there are three categories of primitive type one-arity specializations of the Function<T, R> interface, each distinguished by a naming scheme. Also, these primitive type one-arity specializations do not define any default methods. These one-arity generic functions have the functional method apply: primitive … Read morePrimitive Type Specializations of Function – 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

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

Accessing Local Variables in the Enclosing Context – Functional-Style Programming

Accessing Local Variables in the Enclosing Context All variable declarations in a lambda expression follow the rules of block scope. They are not accessible outside the lambda expression. It also means that we cannot redeclare local variables already declared in the enclosing scope. In Example 13.2, redeclaring the parameter banner and the local variable words … Read moreAccessing Local Variables in the Enclosing Context – Functional-Style Programming

Composing Functions – Functional-Style Programming

Composing Functions Both the default methods compose() and andThen() of the Function<T, R> interface return an instance of a Function that is created from the caller function (i.e., the function on which the method is invoked) and the argument function (i.e., the function that is passed as an argument to the method). The two methods … Read moreComposing Functions – Functional-Style Programming