【问题标题】:SortedSet in Grails doesn't workGrails 中的 SortedSet 不起作用
【发布时间】:2010-11-27 15:52:44
【问题描述】:

我想在 Grails 中使用 SortedSet,但我得到的只是一个 MissingMethodException。

包含排序集的类如下所示:

class SystemUser {

    SortedSet organisations
    // ... some other fields

    static hasMany = [organisations: Organisation]
    static belongsTo = [Organisation]

}

...以及像这样实现Comparable 的类:

class Organisation implements Comparable {

    String name
    // ... some other fields

    static hasMany = [users: SystemUser]

    int compareTo(other) {
        return name.comparteTo(other.name)
    }

}

当我尝试保存 SystemUser 对象时,我收到以下异常消息:

groovy.lang.MissingMethodException: No signature of method: java.lang.String.comparteTo() is applicable for argument types: (java.lang.String) values: [ABC]
Possible solutions: compareTo(java.lang.String), compareTo(java.lang.Object)

我的示例与example from the official reference 几乎相同。

【问题讨论】:

    标签: java grails groovy comparable sortedset


    【解决方案1】:

    没有方法签名: java.lang.String.comparteTo() 是 适用于参数类型

    现在看到问题了吗?

    【讨论】:

    • hmpf,只是一个错字! (compar_t_eTo) 欢迎来到动态类型的世界 ;-)
    • 或使用 IDE 尝试提供更多帮助;)
    • 我试过 NetBeans,它在 Groovy 模式下非常慢,SpringSource Toolsuite 显示了很多不存在的错误,但现在我在尝试 IntelliJ,感觉很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    相关资源
    最近更新 更多