override library method using Scala Implicit

前端 未结 1 1660
说谎
说谎 2021-01-19 00:15

I\'m using a library which has a class Product like

class Product {
   def toString() = \"Whatever\"  
}

I want to override th

相关标签:
1条回答
  • 2021-01-19 00:57

    Implicits are used if scala compiler cannot find method without it, so you can`t override methods with implicits. Use inheritance for this tasks.

    class NewProduct extends Product {
        override def toString() = "an-other whatever"
    }  
    
    0 讨论(0)
提交回复
热议问题