本文介绍了条件隐式定义Scala的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须解决这个问题,但是我找不到正确的答案.
I have to solve this quinz but i can't find the correct answer.
trait Physics { implicit def air: Gaz, implicit def condense(implicit gaz: Gaz): Liquid, implicit def freeze(implicit liquid: Liquid): Solid implicitly[Solid] }您可以使用显式编写的推断参数重写最后一行吗?
Can you rewrite the last line with the inferred parameter explicitly written?
提示:应该看起来像 隐式[固体](...
Hint: It should look like implicitly[Solid](...
非常感谢您!
推荐答案这里是一个提示:首先考虑implicitly只是一种与其他方法一样的方法
Here is a hint: first consider implicitly is just a method like any other
def implicitly[T](implicit e: T): T = e让我们删除关键字implicit这样
def implicitly[T](e: T): T = e给出implicitly只是一个带有参数的方法,请考虑如何使编译器满意并让方法implicitly返回Solid?
Given implicitly is just a method taking arguments, think about what would you have to do to make compiler happy and have method implicitly return a Solid?
更多推荐
条件隐式定义Scala
发布评论