What is the difference between X[Any]
and X[_]
?
Let's consider, for example, two functions below:
def foo(x:X[_]){}
def foo(x:X[Any]){}
What is exactly the difference between these declarations above?
The first is an existential type, and the second is a normal type. The first syntax actually means this:
def foo(x:X[t] forSome { type t }){}
What this means is that x
is of type X[t]
, where t
can be any unspecified type t
.
Intuitively, X[_]
means the type parameter of X
is irrelevant, whereas X[Any]
says it must be Any
.
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