Java Reference
In-Depth Information
ory method for ThreadLocal that takes a lambda expression, letting you create a new
ThreadLocal without the syntactic burden of subclassing.
a. Find the method in Javadoc or using your IDE.
b. The Java DateFormatter class isn't thread-safe. Use the constructor to create
a thread-safe DateFormatter instance that prints dates like this:
“01-Jan-1970”.
3. Type inference rules . Here are a few examples of passing lambda expressions into
functions. Can javac infer correct argument types for the lambda expressions? In oth-
er words, will they compile?
a. Runnable helloWorld = () -> System.out.println("hello world");
b. The lambda expression being used as an ActionListener :
JButton button = new
new JButton ();
button . addActionListener ( event ->
System . out . println ( event . getActionCommand ()));
c. Would check(x -> x > 5) be inferred, given the following overloads for
check ?
interface
interface IntPred
IntPred {
boolean
boolean test ( Integer value );
}
boolean
boolean check ( Predicate < Integer > predicate );
boolean
boolean check ( IntPred predicate );
TIP
You might want to look up the method argument types in Javadoc or in your IDE in order
to determine whether there are multiple valid overloads.
Search WWH ::




Custom Search