import grails.transaction.Transactional
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
@CompileStatic
@Transactional
abstract class BaseService<T> implements DefaultDomainServiceMethods<T> {
DBService DBService
@CompileDynamic
boolean isNew(def domainInstance) {
return !domainInstance.id
}
}
在grails run-app
上导致以下错误|Compiling 1 source files
.Error
|
Compilation error: startup failed:
/samson/projects/samsongit/grails/samsonmain/grails-app/services/samson/BaseService.groovy: 14: [Static type checking] - No such property: id for class: java.lang.Object
@ line 14, column 17.
return !domainInstance.id
^
1 error
显然@CompileDynamic不起作用。在grails run-app运行后更改此设置时,控制台会在错误消息循环中获取堆栈溢出。
Intellij不会报告任何错误。