条件隐式定义Scala

编程入门 行业动态 更新时间:2024-10-25 16:18:58
本文介绍了条件隐式定义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

本文发布于:2023-11-10 22:49:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576677.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   条件   隐式   Scala

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!