what is the difference between `interface Foo<T...
# announcements
l
what is the difference between
interface Foo<T : Any>
and
interface Foo<T>
?
p
The first one constraints T to a type in a
non nullable
subset of
Any
. The second one accepts T to be a
nullable
type in a subset of
Any?
l
Just to clarify, Foo<T> implies that T can be nullable?
p
This is from official docs. https://kotlinlang.org/docs/reference/generics.html#generic-constraints The default upper bound (if none specified) is Any? However, the best way to assure it is testing it on your own.
s
@liminal yes,
Foo<T>
is shorhand for
Foo<T: Any?>
, so T can be a nullable Type (but of course you could restrict that later when implementing Foo
StrFoo: Foo<String>
wouldn’t be nullable while
NStrFoo: Foo<String?>
would be)
l
Thanks guys!