search

Home  >  Q&A  >  body text

java - What does the <K> after static in instance method mean?

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

为情所困为情所困2754 days ago667

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你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.

    reply
    0
  • 某草草

    某草草2017-05-17 10:03:12

    The generics in

    java represent type parameters

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-17 10:03:12

    This is a static generic method in java

    reply
    0
  • Cancelreply