Scala is new here. I am very confused about why the code below throws an exception. I know I Function1[Int, Int]have an abstract applytype method Int => Intthat needs to be defined. Doesn't that make it lower oddfunc? Why x(3)doesn't it call the specific method applydefined in oddfunc?
Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> trait oddfunc extends Function1[Int,Int] {
| def apply(a: Int): Int = a+3
| }
defined trait oddfunc
scala> val x = new oddfunc{}
x: oddfunc = <function1>
scala> x(3)
java.lang.AbstractMethodError: $anon$1.apply$mcII$sp(I)I
at oddfunc$class.apply(<console>:8)
at $anon$1.apply(<console>:8)
... 43 elided
source
share