【问题标题】:Why Fantom compiler complains about a class that has a Func field?为什么 Fantom 编译器抱怨具有 Func 字段的类?
【发布时间】:2017-06-28 07:08:53
【问题描述】:

我编写了一个 Fantom 脚本,它定义了一堆类。由于我可以成功运行脚本,我决定将其转换为适当的 Fantom 项目,但其中一个类无法编译,错误消息是:

Expected expression, not '|'

该类具有这种形式:

class MyClass
{
    const Func myFunc := |Foo foo, Bar bar| {
        // do stuff
    }

    MyType myVar := MyType()

    Void main() {
        // do more stuff
    }

}

我不明白为什么当这个类是 Fantom 项目的一部分时编译器会报错,但如果是 Fantom 脚本的一部分却不会。有没有人能解释一下?

谢谢

【问题讨论】:

    标签: fantom


    【解决方案1】:

    这只是 Fantom 的错误信息。它实际上是在抱怨 FooBar 类不存在。将以下内容添加到您的项目中,一切都应该可以编译。

    class Foo {}
    class Bar {}
    class MyType {}
    

    【讨论】:

    • 非常感谢史蒂夫。你说的很对!这是一个糟糕的错误消息。 Foo 类实际上存在于 MyClass 旁边,但 Bar 类属于另一个我错过了“使用”语句的 pod。
    猜你喜欢
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 2012-03-28
    • 2016-11-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 2019-06-16
    相关资源
    最近更新 更多