In the process of writing my post yesterday, I realised that the biggest annoyance of Groovy is really its type system. Today, I came across this, ahm, surprising, string-to-integer conversion:
class A {
String abc = "1"
int getAbc() {
return abc
}
}
def a = new A()
println a.getAbc() // prints ... "49" ?!?
class B {
String abc = "1"
int getAbc() {
return abc.toInteger()
}
}
def b = new B()
println b.getAbc() // prints "1"
By the way, if the string is “2″ in the first example, you get …. 50. Tada!
Well I don’t know about you, but I’ll be rather glad when I have finished the coursework (which is the only reason why I use Groovy … we have to), which should be soon :)