入門小白求問(新手貼,若有不合規範請指出,謝謝了):
Java裡instance method "private static <K> void methodName() {}" 中的<K>是什麼意思?
這裡的return不是void嗎? 為什麼有<K>呢?
問題來源: Data Structures and Algorithms in Java™ Sixth Edition Michael T. Goodrich...page:537(array-based merge-sort)
code:
public static <K> void merge(K[] S1, K[] S2, K[] S, Comparator<K> comp) {
int i = 0, j = 0;
while(i + j < S.length) {
if (j == S2.length || (i<S1.length && comp.compare(S1[i], S2[j]<0))
S[i+j] = S[i++];
else
S[i+j]=S2[j++];
}
}
多謝各位回答, 找到一個很詳細的介紹:http://blog.csdn.net/jungle_h...