Java Reference
In-Depth Information
In the following code, each element of a List of Integers is passed to the constructor of Apple
using a similar map method we defined earlier, resulting in a List of apples with different
weights:
If you have a two-argument constructor, Apple(String color, Integer weight), it fits the signature
of the BiFunction interface, so you can do this,
which is equivalent to
The capability of referring to a constructor without instantiating it enables interesting
applications. For example, you can use a Map to associate constructors with a string value. You
can then create a method giveMeFruit that, given a String and an Integer, can create different
types of fruits with different weights:
 
Search WWH ::




Custom Search