I am reading State of the Lambda: Libraries Edition, and am being surprised by one statement:
Under the section Streams, there is the following:
List<Shape> blue = shapes.stream()
.filter(s -> s.getColor() == BLUE)
.collect(Collectors.toList());
The document does not state what shapes
actually is, and I do not know if it even matters.
What confuses me is the following: What kind of concrete List
does this block of code return?
- It assigns the variable to a
List<Shape>
, which is completely fine.
stream()
nor filter()
decide what kind of list to use.
Collectors.toList()
neither specifies the concrete type of List
.
So, what concrete type (subclass) of List
is being used here? Are there any guarantees?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…