https://kotlinlang.org logo
Title
o

oday

07/06/2021, 9:04 AM
what’s the difference between
interface Stack<T : Any>
and
interface Stack<T>
?
T
already means literally anything
m

Matteo Mirk

07/06/2021, 9:08 AM
by default T implies
T : Any?
so includes nullable types. Your first declaration excludes nullable types from the domain.
o

oday

07/06/2021, 9:10 AM
I see, nice ok
true, if you go to implement this interface with a class that has type just
T
, feeding that
T
back to Stack<T> will complain
m

Matteo Mirk

07/06/2021, 9:20 AM
not sure I understand what you mean, sorry 😕
o

oday

07/06/2021, 9:20 AM
means I tried it, it’s as you said 👍🏻
m

Matteo Mirk

07/06/2021, 9:23 AM
okay good! So the compiler prevents you from declaring a
Stack<Int?>
if you used the first definition, right?
o

oday

07/06/2021, 9:25 AM
correct
👌 2