Reputation: 2098
Please explain this in Scala.
If I have a
trait A
I cannot do a
val a = new A
But this example trait,
trait DS[-In, +Out]{def apply(i: In): Out}
can have an instance of
val t1 = new DS[Any, Int]{def apply(i: Any) = i.toString.toInt}
How is this allowed?
Upvotes: 0
Views: 1387
Reputation: 8529
What is happening is that by providing a class body you are creating an anonymous class inline that extends the trait.
Upvotes: 8