首页 > 解决方案 > Grails 4:@GrailsCompileStatic 注释不起作用

问题描述

从 grails 3.3.5 迁移 -> grails 4.0.0.M2

我的类已经用@GrailsCompileStatic& 进行了注释,它在 3.3.5 中编译时没有任何问题。

许多其他类也显示由 groovy 额外提供的方法的错误,例如Date.parse()orDate.format()Date.minus()

错误:

FileCommandReader.groovy: 163: [Static type checking] - Cannot find matching method java.util.Date#parse(java.lang.String, java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 163, column 17.
                Date expiry = Date.parse("HH:mm:ss", cols[2]);

标签: grailsgrails-4

解决方案


这真的不是@GrailsCompileStatic问题。Grails 4.0 使用 Groovy 2.5.6。以下代码无法使用 Groovy 2.5.6 编译...

import groovy.transform.CompileStatic

@CompileStatic
class Helper {

    void someMethod() {
        Date.parse '', ''
    }
}

Grails 3.3.5 使用 Groovy 2.4.15,上面的代码在 Groovy 2.4.15 中有效。


推荐阅读