Ask a beginner (novice post, please point out if there are any non-standards, thank you):
<K> in instance method "private static <K> void methodName() {}" in Java What does it mean?
Isn’t return here void? Why is there <K>?
Source of the problem: 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++];
}
}
Thank you for your answers, I found a very detailed introduction: http://blog.csdn.net/jungle_h...
世界只因有你2017-05-17 10:03:12
This is a generic type parameter, used to indicate that the "K" used in the subsequent method declaration is not an actual class.