Out of curiosity I tried to run the following:
def someFun[_](a:Int) = a
To my surprise, no errors or warnings got issued and it runs the way you expect it to (which is fine I suppose) but is it normal that the compiler does not understand the redundancy of the type parameter or perhaps it means something that makes it (semantically?) different from this:
def someFun(a:Int) = a
The compiler generates this:
def someFun(a: Int): Int = a;
But this is not because the compiler knows that this is unused, but because of the type erasure. You can check things like this with the -print
option of the compiler. It is also not surprising, that this works, because it is just an unused type parameter.
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