繁体   English   中英

Scala隐式练习

[英]Scala implicits exercises

我正在从https://www.scala-exercises.org/std_lib/implicits进行练习

对于以下问题,我的答案似乎不正确,但我不知道为什么。

object MyPredef {

  class KoanIntWrapper(val original: Int) {
    def isOdd = original % 2 != 0

    def isEven = !isOdd
  }

  implicit def thisMethodNameIsIrrelevant(value: Int) =
    new KoanIntWrapper(value)
}

import MyPredef._
//imported implicits come into effect within this scope
19.isOdd should be(true) //my answer but it seem incorrect
)
20.isOdd should be(false)  //my answer but it seem incorrect

错误是There was a problem evaluating your answer, please try again later.

正确答案分别是truefalse ,因此您的答案是正确的。

您有额外的结束括号:

19.isOdd should be(true) //my answer but it seem incorrect
)  // <-- HERE
20.isOdd should be(false)  //my answer but it seem incorrect

祝您学习Scala好运。


现在检查此练习,一切正常。 因此,这似乎是一个暂时性的问题。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM