Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用@GrailTypeChecked和@GrailsCompileStatic_Grails - Fatal编程技术网

如何使用@GrailTypeChecked和@GrailsCompileStatic

如何使用@GrailTypeChecked和@GrailsCompileStatic,grails,Grails,我有兴趣阅读Grails中的新注释,这些注释在理论上应该提供运行时性能改进,同时仍然允许动态调度,但似乎没有任何效果。我错过了什么 class MyService { @GrailsTypeChecked // or @GrailsCompileStatic def doSomething() { String name = missingVariable } } grails> clean | Application cleaned. grails> com

我有兴趣阅读Grails中的新注释,这些注释在理论上应该提供运行时性能改进,同时仍然允许动态调度,但似乎没有任何效果。我错过了什么

class MyService {

  @GrailsTypeChecked // or @GrailsCompileStatic
  def doSomething() {
    String name = missingVariable
  }
}

grails> clean
| Application cleaned.
grails> compile
| Compiling 1 source files.....
一切都会编译,但在运行时会爆炸?我肯定错过了什么,因为我真的不知道这些新注释是如何工作的。编译器如何计算出什么是错误调用,什么是可以忽略的错误调用(即动态查找器)


我使用的是Grails2.5.0,代码不应该编译。我已经构建了一个简单的应用程序,并将您的代码直接粘贴到该应用程序中,但代码无法为我编译。看

编译器将如何计算出什么是错误调用以及什么是错误调用 是否存在可以忽略的错误呼叫(即动态查找器)


我们有与类型检查器协作的类型检查扩展,因此当类型检查器认为它看到无效代码时,我们的扩展被占用,并且如果扩展能够识别出它类似于动态查找器,那么扩展就有机会将调用转换为动态调用,无法静态调度,但实际上在运行时是有效的。

根据Jeff的评论,似乎存在一个bug,它阻止了@GrailsCompileStatic和@GrailTypeChecked注释在同时存在类级别@Transactional注释时工作。我相信Grails3.0.1已经解决了这个问题(谢谢大家!)

Jeff,谢谢你花时间研究这个问题。我将我的类与您的类进行了比较,我意识到我也在使用事务类级别的注释,它似乎否定了GrailTypedChecked或GrailsCompileStatic注释。请看一看,这是已知的限制吗?如果是这样,可能需要对其进行记录(或者可能我错过了!)如果我不使用事务性注释,代码将按照我的预期进行编译,但域类上的.save()方法似乎仍然会导致问题,即新的DomainClass().save()将给出编译错误,尽管DomainClass.findByName()可以。这是一个已知的bug吗?原始问题中缺少的事务性注释非常重要。这不是已知的或预期的限制,这将是一个bug。我想我知道可能出了什么问题。如果你在网站上提交一个问题,我们可以把它弄清楚。谢谢杰夫,我应该把整个班级贴在这里,吸取教训!我会按要求提交一个问题我想我昨天已经解决了。看见谢谢你的反馈。
| Compiling 8 source files
  [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException:     startup failed:
  [groovyc] /Users/jeff/t/grailscompilestatic/grails-    app/services/demo/MyService.groovy: 9: [Static type checking] - The variable     [missingVariable] is undeclared.
  [groovyc]  @ line 9, column 19.
  [groovyc]        String name = missingVariable
  [groovyc]                      ^
  [groovyc] 
| Compiling 8 source files.
| Error Compilation error: startup failed:
/Users/jeff/t/grailscompilestatic/grails-app/services/demo/MyService.groovy: 9:     [Static type checking] - The variable [missingVariable] is undeclared.
 @ line 9, column 19.
       String name = missingVariable
                     ^

1 error