【问题标题】:Continuations and implicit conversions延续和隐式转换
【发布时间】:2011-02-03 12:22:44
【问题描述】:

我正在尝试延续,我遇到了一个似乎表明@cpsParam 阻止隐式转换的案例。

我有

def v: T @cpsParam[Unit, Unit]
// ...and then later
v must_== 42
// where must_== is from specs/mockito

我得到编译器错误:

must_== is not a member of Int @cpsParam[Unit,Unit]

gist 上提供了更完整的代码示例。

我犯了一个简单的错误吗?

谢谢, 托弗。

【问题讨论】:

    标签: scala continuations implicit-conversion


    【解决方案1】:

    我找不到 must_== 方法的定义位置。但是您可能应该导入隐式转换方法,而不仅仅是类/特征/对象。这意味着,你应该这样写:

    import foo.bar.Bar.convert // OK

    或者这个:

    import foo.bar.Bar._ // OK

    不是这个

    import foo.bar.Bar // Bad: The implicit conversion method is not imported!

    【讨论】:

    • gist 上的示例代码通过它扩展的特征/类将必要的隐式定义带入范围。
    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多