Java Reference
In-Depth Information
yet easy to use way. One last point: although the streams supported by the new
stream API have some similarities with the I/O streams described in Chapter 10 , they
are not the same.
The program produces the following output:
Chapter 14 Self Test
1 . What is the lambda operator?
2 . What is a functional interface?
3 . How do functional interfaces and lambda expressions relate?
4 . What are the two general types of lambda expressions?
5 . Show a lambda expression that returns true if a number is between 10 and 20, inclus-
ive.
6 . Create a functional interface that can support the lambda expression you created in
question 5. Call the interface MyTest and its abstract method testing( ) .
7 . Create a block lambda that computes the factorial of an integer value. Demonstrate its
use. Use NumericFunc , shown in this chapter, for the functional interface.
8 . Create a generic functional interface called MyFunc<T> . Call its abstract method
func( ) . Have func( ) return a reference of type T . Have it take a parameter of type T .
(Thus, MyFunc will be a generic version of NumericFunc shown in the chapter.)
Demonstrate its use by rewriting your answer to question 7 so it uses MyFunc<T>
rather than NumericFunc .
9 . Using the program shown in Try This 14-1 , create a lambda expression that removes
all spaces from a string and returns the result. Demonstrate this method by passing it
to changeStr( ) .
10 . Can a lambda expression use a local variable? If so, what constraint must be met?
Search WWH ::




Custom Search