Grails: println only works sometimes or something

2019-09-02 15:20发布

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

2条回答
Emotional °昔
2楼-- · 2019-09-02 15:50

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.

查看更多
Anthone
3楼-- · 2019-09-02 16:09

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?

查看更多
登录 后发表回答