(Really awful title.)
Anyway: can I somehow make Scala infer the type of b
in 2nd line?
scala> class A[B](val b: B, val fun: B => Unit)
defined class A
scala> new A("123", b => { })
<console>:9: error: missing parameter type
new A("123", b => { })
^
This works as expected after adding the type:
scala> new A("123", (b: String) => { })
res0: A[String] = A@478f6f48
And String
is certainly the expected type:
scala> new A("123", (b: Int) => {})
<console>:9: error: type mismatch;
found : Int => Unit
required: String => Unit
new A("123", (b: Int) => {})
^