Question

Let's say we've got a Foo class in a library we use and want (in a code file of ours) Foo instances to be implicitly cast to String instances whenever a Foo instance is met in a place a String instance is required. How to achieve this in Scala?

Was it helpful?

Solution

Just do this:

implicit def stringFromFoo(foo: Foo): String = foo.toString
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top