【问题标题】:Groovy: Unexpected token ":"Groovy:意外的令牌“:”
【发布时间】:2015-05-03 10:18:00
【问题描述】:

我有这个自动生成的代码行:

EPRole validator: { EPRole r, EPUserEPRole ur ->
            if (ur.EPUser == null) return
            boolean existing = false
            EPUserEPRole.withNewSession {
                existing = EPUserEPRole.exists(ur.EPUser.id, r.id)
            }
            if (existing) {
                return 'userRole.exists'
            }
        }

当我尝试编译代码时,我得到82: unexpected token: validator @ line 82, column 10.

我是 groovy 的新手,因此不胜感激。

【问题讨论】:

  • 应该是epRole? EPRole 将是类
  • 啊,现在我明白了。整个类是自动生成的,你是对的,错误取决于大写和小写。我怎样才能接受你的答案是正确的?

标签: groovy


【解决方案1】:

您应该将具有正确类型和名称的属性添加到类中。第一个大写字母用于类(或一般类型)。所以在你的EPUserEPRole 中应该有这样的属性:

EPRole epRole

然后为epRole 添加验证器。关注案例。

上面的代码会使 groovy 解析器混淆为定义类型为 EPRole 的属性 validator 后跟 :,因此会出现错误(否则它会尝试使用映射调用 EPRole 方法,具体取决于上下文)。

【讨论】:

    猜你喜欢
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2016-05-03
    • 2018-04-17
    相关资源
    最近更新 更多