James Whitehead
01/01/2022, 7:36 PM<T>
and the second parameter is "an instance or implementation of T"?
• Also kind of related question: When should one use <T>
vs <T : Any>
, I'm not really sure what the difference is?
Thanks in advance 🙂Joffrey
01/01/2022, 8:08 PMfun <T, U : T> someFunction() {
}
<T>
denotes any type including nullable types, while <T : Any>
forbids nullable types for T, because nullable types are not subtypes of Any
James Whitehead
01/01/2022, 9:33 PMU
, how did you know to use that particular letter?Joffrey
01/01/2022, 10:32 PMT
is a very classic example, because it's T as in "Type". U
is simply the next letter in the alphabet. Sometimes other letters make sense. For instance K
and V
for the types of the keys and values in a map, or E
for the element type in a collection.Jacob
01/02/2022, 12:40 AMJames Whitehead
01/02/2022, 6:09 AMJoffrey
01/02/2022, 7:30 AMMatteo Mirk
01/04/2022, 11:49 AM