4 ms·
> like the compiler is taking type information and using it to make implicit casts throughout the program. It's not a cast. Rather, it's an inferred/omitted ty
by oconnor663 6y ago
> like the compiler is taking type information and using it to make implicit casts throughout the program.
It's not a cast. Rather, it's an inferred/omitted type parameter. In this case, the collect() method is actually collect::<ContainerType>(). So it's not that collect returns something to be cast, but rather that there is a different collect() implementation for each target type. When the compiler is able to infer the target type unambiguously -- for example here, because you assign it to a typed variable -- then you don't have to specify it.
- caditinpiscinam 6y agoAh, I see - the "inferred/omitted type parameter" is the part I was missing. Really no different than Arrays.asList in my previous comment. Thanks!