I have encounter a code snippt
putAll(Map<? extends K, ? extends V> map)
on the Android developer site, I know that the K and V are placeholders, but what does the question mark ? mean? Does it mean that the param must be a reference type or something else?
The ternary conditional operator ?: allows us to define expressions in Java. It's a condensed form of the if-else statement that also returns a value.
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.13-Sept-2022.
The symbol & denotes the bitwise AND operator. It evaluates the binary value of given numbers. The binary result of these numbers will be returned to us in base 10. When the & operator starts its operation, it will evaluate the value of characters in both numbers starting from the left.
It is used in the new short hand for/loop final List<String> list = new ArrayList<String>(); for (final String s : list) { System.out.println(s); }
In Java ?
is known as Wildcard, you can use it to respresent an unknown type
.
The upper bounded wildcard, , where Foo is any type, matches Foo and any subtype of Foo. The process method can access the list elements as type Foo:
public static void process(Map<? extends A> list) {
/* code */
}
In your case it is known as Upper bounded wildcard.
http://docs.oracle.com/javase/tutorial/java/generics/upperBounded.html
putAll(Map<? extends K, ? extends V> map)
It means, that any object, that can extend the A
class is applicable in this conditionn.
It's a wild card for class type, in your case
putAll(Map<? extends K, ? extends V> map)
the first question mark indicates that any type which extends K is applicable, and so on.
You can read more here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With