0

I'm new to scala and trying hard to undestand some code. In the code below what does the type Signal[_] mean? how is it different from type Signal[T]?

class Signal[T](expr: => T) {.......}

object NoSignal extends Signal[Nothing](???) {
  override def computeValue() = ()
}

object Signal {
  val caller = new DynamicVariable[Signal[_]](NoSignal)
  def apply[T](expr: => T) = new Signal(expr)
}

Thanks

  • this post about higher kinded types helped me to understand my own question. http://stackoverflow.com/questions/6246719/what-is-a-higher-kinded-type-in-scala – Priyan Chandrapala Apr 14 '17 at 17:44

1 Answers1

1

Here's a great summary of all the uses of underscore.

In this case, I think it denotes an existential type, or a wildcard (a "don't care" or "meh ..." type).

val m:Map[_,_] = Map[String,Integer]()

... the information about the specific types of the key and value are lost. You can call this map's size method, but not any methods that refer to the key or values types in the method's signature.

Community
  • 1
  • 1
user48956
  • 14,850
  • 19
  • 93
  • 154