The problem is that K
and V
aren't really "repeated", at least not any more than a variable declaration and a use of that same variable are "repetition".
The way to think of this is that you declare the generic types K
and V
, and then you use those declared generic types in the definition of the generic type M
. So, you don't declare the generic type K
or V
more than once: Rather, you declare each of them once and then refer to them in a declaration of something else.
To look at it another way, the number of generic types here is still three, namely K
, V
, and M
. M
happens to be defined in terms of K
and V
, but you didn't have to define M
that way.
I should add that if you are a proponent of type inference, you might view the declaration and the use of the same variable as unnecessary repetition. However, if you're accustomed to programming in Java (or C, or C++, or many, many other languages), then you're probably accustomed to declaring variables before you use them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…