Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding of '_' (underscore) in Scala as a type variable

Tags:

scala

In Scala I can use underscore as a type variable in function, for instance.

  def fun[_, _]() = {
    // ?
  }

  fun[Int, String]()

Is it so useful in real life programming? How could it be useful for me?

like image 349
Finkelson Avatar asked Nov 24 '25 17:11

Finkelson


1 Answers

Is it so useful in real life programming?

No, it isn't.

How could it be useful for me?

To confuse people. You could theoretically use it to mark an unused type parameter when e.g. overriding a method, but I don't think I've ever seen this.

like image 107
Alexey Romanov Avatar answered Nov 26 '25 08:11

Alexey Romanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!