Forum Stats

  • 3,750,546 Users
  • 2,250,192 Discussions
  • 7,867,003 Comments

Discussions

basic problem?

Murray9654
Murray9654 Member Posts: 486
edited Feb 26, 2013 9:40AM in Generics
Hi while going through docs i found the following method
public static <K, V> boolean compare(Pair<K, V> p1, Pair<K, V> p2) {
        return p1.getKey().equals(p2.getKey()) &&
               p1.getValue().equals(p2.getValue());
    }
I am not able to understand why they have defined <K,V> infront of the return type boolean? how to understand this and what is the meaning of this?

Edited by: Muralidhar on Feb 26, 2013 4:53 PM

Best Answer

  • EJP
    EJP Member Posts: 32,920 Gold Crown
    Accepted Answer
    That is the syntax of the Java language when defining a generic method. The type parameters are defined, and bounded if necessary, before the return type, and then referenced in parameters or the method body, or both.

Answers

This discussion has been closed.