Finkelson
Finkelson

Reputation: 3013

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

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?

Upvotes: 3

Views: 640

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170713

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.

Upvotes: 1

Related Questions