Grails: println only works sometimes or something

1.6k views Asked by At

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

There are 2 answers

5
Steve On

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?

0
Mikey On

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.