groovy静态类 [英] groovy static class

查看:243
本文介绍了groovy静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个文件sample.groovy中,'static'做了什么?

  static class froob {
}

Groovy代码可以用'static'编译,或者不用它。

解决方案

完全没有区别。为了测试,我创建了一个groovy类,并将javap -verbose StaticTest的输出传送到一个文件中。然后在class def之前加上static并将其传送到第二个文件。然后我分析了这两个文件。唯一的区别是那些与长类ID关联的独特ID,它会为每个类生成新的。


What does the 'static' do in this file, sample.groovy?

static class froob {
}

The groovy code compiles fine with 'static' or without it.

解决方案

There is absolutely no difference. The static in this situation is ignored.

To test, I created a groovy class and piped the output of "javap -verbose StaticTest" to a file. Then put "static" before the class def and piped that to a 2nd file. I then diffed the two files. The only differences were those unique ids that are associated with the long class ID that gets generated new for every class.

这篇关于groovy静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆