At the moment, Groovy++ will automatically coerce some types to other types,
but it seems to be implemented inconsistently. I would prefer to see no
auto-coercion at all in Groovy++ (we have the 'as' operator after all), but if
auto-coercion is kept, it should at least be minimal and consistent.
There's my original e-mail to the mailing list:
-----------------
I just noticed that this works:
int i = "1"
but this doesn't:
int i = "10"
Is that intentional? If so, why? I do find auto-coercion a little bit
disconcerting in a static language at the best of times, but the above seems
particularly obtuse and confusing. Also, the fact that everything can seemingly
be automatically coerced to a String makes me wonder about the sense in
declaring anything of type String. Does it only happen at variable
initialisation time?
In fact, I noticed that these are fine:
String str = 1000
String str2 = new Date()
String str3 = new File("")
as is:
String myMethod(String str) { return str.reverse() }
println myMethod(1000)
but a Date cannot be passed as an argument:
println myMethod(new Date()) // <-- compile error
Note that I was testing the above in STS, but I'm assuming that the compile
errors are coming from Groovy++ compiler.
Original issue reported on code.google.com by p.ledbr...@gmail.com on 15 May 2011 at 5:19
Original issue reported on code.google.com by
p.ledbr...@gmail.com
on 15 May 2011 at 5:19