What does the question mark mean in java?

I have snippt code

putAll(Map<? extends K, ? extends V> map)

on an Android developer , I know that K and V are placeholders, but what does the sign mean ? . Does this mean that the parameter must be a reference type or something else?

+4
source share
2 answers

In Java, known as Wildcard, you can use it to send . ?unknown type

The upper bounded wildcard, where Foo is any type, matches Foo and any subtype of Foo. A process method can access list items as a type of Foo:

public static void process(Map<? extends A> list) {
  /* code */
}

In your case, this is called the top restricted template.

http://docs.oracle.com/javase/tutorial/java/generics/upperBounded.html

putAll(Map<? extends K, ? extends V> map)

, , A, n.

+4

,

putAll(Map<? extends K, ? extends V> map)

, , K, ..

+5

Source: https://habr.com/ru/post/1541999/


All Articles