问题
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](...
Thank you so much!
回答1:
Here is a hint: first consider implicitly
is just a method like any other
def implicitly[T](implicit e: T): T = e
Lets remove the keyword implicit
such that
def implicitly[T](e: T): T = e
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
?
来源:https://stackoverflow.com/questions/61170151/conditional-implicit-definitions-scala