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

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

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 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 Predicate – Functional-Style Programming

Primitive Type Specializations of Predicate<T> The functional interfaces IntPredicate, LongPredicate, and DoublePredicate evaluate predicates with int, long, and double arguments, respectively, avoiding the overhead of boxing and unboxing of primitive values (see Table 13.5). The primitive type versions are not subinterfaces of the Predicate<T> interface. Click here to view code image Predicate<Integer> isEven = i … Read morePrimitive Type Specializations of Predicate – Functional-Style Programming

Primitive Type Specializations of Supplier – Functional-Style Programming

Primitive Type Specializations of Supplier<T> The primitive type versions of the generic supplier interface are appropriately named with a prefix to indicate the type of primitive value returned by their functional methods. For example, the integer supplier is named IntSupplier. Their functional methods are also appropriately named with a postfix to indicate the type of … Read morePrimitive Type Specializations of Supplier – 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

Lambda Expressions and Anonymous Classes – Functional-Style Programming

13.3 Lambda Expressions and Anonymous Classes As we have seen in this chapter so far, both anonymous classes and lambda expressions can be used to provide implementation of functional interfaces. Example 13.3 illustrates using both anonymous classes and lambda expressions for this purpose. A common operation on elements in a collection is to select those … Read moreLambda Expressions and Anonymous Classes – 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

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