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 { }
Error creating object "because the method of the method in the Base type => String class is not defined"
The indicated error is fixed by the 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 the Scala class, when I define the 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 the error "an ambiguous reference to an overloaded definition, as a method method in the Trait attribute of type () (implicit i: String) A String method and a method in the Trait attribute of type () Argument types with strings ()"
What is the difference in both of these scenarios that cause the compiler to behave differently? How to solve this problem?
0n4li source share