The following code gives an error:
package test
trait Base {
def method:String
}
trait Trait extends Base {
def method()(implicit i:String):String = { "2" }
}
object Object extends Trait {
}
The error is "object creation impossible, since method method in class Base of type => String is not defined"
The above error is fixed by following code
package test
trait Base {
def method:String
}
trait Trait extends Base {
def method:String = method()("String") // Over loading
def method()(implicit i:String):String = { "2" }
}
object Object extends Trait {
}
Now instead of Scala class, when I define a Java interface as follows:
// Java Code
package test;
public interface JBase {
String method();
}
// Scala Code
package test
trait Trait extends JBase {
def method:String = method()("10")
def method()(implicit i:String):String = { "2" }
}
object Object extends Trait {
}
I get an error "ambiguous reference to overloaded definition, both method method in trait Trait of type ()(implicit i: String)String and method method in trait Trait of type ()String match argument types ()"
What is the difference in both these scenarios that makes the compiler behave differently? How do I solve this issue?