문제

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?

도움이 되었습니까?

해결책

Just do this:

implicit def stringFromFoo(foo: Foo): String = foo.toString
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top