https://kotlinlang.org logo
#announcements
Title
# announcements
l

liminal

11/15/2019, 3:13 AM
what is the difference between
interface Foo<T : Any>
and
interface Foo<T>
?
p

Pablichjenkov

11/15/2019, 3:32 AM
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

liminal

11/15/2019, 5:16 AM
Just to clarify, Foo<T> implies that T can be nullable?
p

Pablichjenkov

11/15/2019, 5:55 AM
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

Stephan Schroeder

11/15/2019, 11:03 AM
@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

liminal

11/15/2019, 1:00 PM
Thanks guys!