java - What does the <K> after static in instance method mean?
为情所困
为情所困 2017-05-17 10:01:12
0
3
688

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...

为情所困
为情所困

reply all(3)
世界只因有你

This is a generic type parameter, used to indicate that the "K" used in the subsequent method declaration is not an actual class.

某草草

The generics in

java represent type parameters

巴扎黑

This is a static generic method in java

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template