WhydoesthesignatureofgroupBycontainonlyonegeneric?
This is the method signature:
groupBy[K](f: (A) ? K): immutable.Map[K, Repr]
Shouldn't the following:
groupBy[A, K](f: (A) ? K): immutable.Map[K, Repr]
be more appropriate since its taking a collection of A ?
回答
There is no need to defined [A] type parameter on the methods level, because it's defined on the on class level e.g:
sealed abstract class List[+A]
So when method is declared like this groupBy[K](f: (A) ? K): immutable.Map[K, Repr] A is already known.
THE END
二维码