Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我们Foo在使用的库中有一个类,并且希望(在我们的代码文件中)实例在需要实例的地方遇到实例时Foo隐式转换为实例。如何在 Scala 中实现这一点?StringFooString
Foo
String
只需这样做:
implicit def stringFromFoo(foo: Foo): String = foo.toString