I\'m trying to define a class with some methods taking an implicit parameter :
object Greetings {
def say(name: String)(implicit greetings: String): String = g
I've found a workaround:
class Greetings(implicit val greetings: String = "hello") {
def say(name: String): String = greetings + " " + name
}
Like this I can have a default value and override it if I want:
new Greetings().say("loic") //> res0: String = hello loic
implicit val greetings = "hi" //> greetings : java.lang.String = hi
new Greetings().say("loic") //> res1: String = hi loic
new Greetings()("coucou").say("loic") //> res2: String = coucou loic
Note: new Greetings()("coucou") is working, not new Greetings("coucou") , because of a syntax strangeness explained here.