Default type-parametrized function literal class parameter
Posted
by doom2.wad
on Stack Overflow
See other posts from Stack Overflow
or by doom2.wad
Published on 2010-03-23T20:02:14Z
Indexed on
2010/03/23
21:33 UTC
Read the original article
Hit count: 311
Is this an intended behavior or is it a bug? Consider the following trait (be it a class, doesn't matter):
trait P[T] {
class Inner(val f: T => Unit = _ => println("nope"))
}
This is what I would have expected:
scala> val p = new P[Int] {
| val inner = new Inner
| }
p: java.lang.Object with P[Int]{def inner: this.Inner} = $anon$1@12192a9
scala> p.inner.f(5)
nope
But this?
scala> val p = new P[Int] {
| val inner = new Inner() {
| println("some primary constructor code in here")
| }
| }
<console>:6: error: type mismatch;
found : (T) => Unit
required: (Int) => Unit
val inner = new Inner() {
^
© Stack Overflow or respective owner