Grails: println only works sometimes or something

我与影子孤独终老i 提交于 2019-12-12 06:03:17

问题


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

回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/8884569/grails-println-only-works-sometimes-or-something

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!