April 2018
Intermediate to advanced
396 pages
11h 8m
English
As expected, the previous problem does not exist when input parameters to the methods differ either by type or by count since this is a new signature. However, the problem will still be there if we have the following two methods in our traits:
def value(a: Int): Int = a // in trait Adef value(a: Int): String = a.toString // in trait B
You will be surprised to see that the approach we used will not work here. If we decide to override only the value method in the A trait, we will get the following compilation error:
Error:(19, 16) overriding method value in trait B of type (a: Int)String; method value has incompatible type override def value(a: Int): Int = super[A].value(a) ^
If we override ...
Read now
Unlock full access