If you can't do what Shadowlands suggests due to Base and Sub being Java types, you can just reduce the priority of the BaseWriter
implicit by moving it up the inheritance chain:
trait LowPriorityImplicits { implicit object BaseWriter extends Writer[Base] }
object AmbImplicits extends LowPriorityImplicits {
implicit object SubWriter extends Writer[Sub]
def foo[T](t: T)(implicit ev: Writer[T]) {
println(s"foo $t $ev")
}
def main(args: Array[String]) {
val base = new Base
val sub = new Sub
foo(base)
foo(sub)
}
}