Grails: println 仅有时有效
我创建了一个全新的 grails 项目并将其放入引导程序中:
ExpandoMetaClass.enableGlobally()
Integer.metaClass.precision = {->return 1}
println 3.precision()
println "rofl"
println 15.precision()
它执行了我所期望的操作,运行应用程序打印:
1
rofl
1
但是如果我取出 println "rofl"
它不会在那一刻打印一。它只打印一个 1,没有 rofl...WTF?
再说一次,因为这对我来说没有任何意义,所以这段代码:
ExpandoMetaClass.enableGlobally()
Integer.metaClass.precision = {->return 1}
println 3.precision()
//println "rofl"
println 15.precision()
打印:
1
I make a brand new grails project and put this in the bootstrap:
ExpandoMetaClass.enableGlobally()
Integer.metaClass.precision = {->return 1}
println 3.precision()
println "rofl"
println 15.precision()
And it does what I expect, run-app prints:
1
rofl
1
But if i take out the println "rofl"
it won't print that second one. It just prints one 1 without the rofl... WTF?
Again, becasue this doesn't make any sense to me, this code:
ExpandoMetaClass.enableGlobally()
Integer.metaClass.precision = {->return 1}
println 3.precision()
//println "rofl"
println 15.precision()
prints:
1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
麦基,我想不出原因。可以换个环境试试吗?我只是在 Groovy Version: 1.8.0 JVM: 1.6.0_20、Win7 和 Grails 2 BootStrap 以及 Grails Controller 操作下快速尝试了这一点,很遗憾地说“它适用于我的”。所以我能想到的是它在某种程度上与您正在使用的版本或它的设置方式有关。你怎么运行这个?
Mikey, I can't think of a reason why. Can you try in a different environment? I just tried this quickly under Groovy Version: 1.8.0 JVM: 1.6.0_20, Win7 and Grails 2 BootStrap and a Grails Controller action and sorry to say "it works on mine". So all I can think is that its somehow related to the version you are using or how it is setup. How are you running this?
这是ubuntu默认设置,与JVM无关。如果它们相同,控制台将不会重复行。当我记得如何关闭它时会更新这个答案。
This is an ubuntu default setting and has nothing to do with JVM. The console won't repeat lines if they are the same. Will update this answer when I remember how to turn it off.