Groovy:意外的标记";:&引用;

Groovy:意外的标记";:&引用;,groovy,Groovy,我有自动生成的代码行: EPRole validator: { EPRole r, EPUserEPRole ur -> if (ur.EPUser == null) return boolean existing = false EPUserEPRole.withNewSession { existing = EPUserEPRole.exists(ur.EPUser.id, r.id

我有自动生成的代码行:

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新手,非常感谢您的帮助

您应该向类添加具有正确类型和名称的属性。第一个大写字母表示类(或一般类型)。因此,在
EPUserEPRole
中应该有这样一个属性:

EPRole epRole
然后为
ePro
添加验证器。注意这个案子


上面的代码会使groovy解析器混淆,从而定义类型为
EPRole
的属性
validator
,后面跟一个
,因此会出现错误(或者它会根据上下文尝试用映射调用方法EPRole)。

应该是EPRole吗?EPRole应该是类啊,现在我明白了。整个类是自动生成的,错误取决于大写字母和小写字母,这是正确的。我怎么能认为你的回答是正确的呢?