Reputation: 83
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
Upvotes: 0
Views: 81
Reputation: 15794
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.
Upvotes: 1