Scala newbie here. I'm a lot confused about why the below code throws an exception. I know Function1[Int, Int] has an abstract apply method of type Int => Int that needs to be defined. Doesn't the below oddfunc do that? Why doesn't x(3) call the concrete apply method defined 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
traitwithclassyour code works fine on my machine. If I usetraitI get the same error.