groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ocs@ocs" <>
Subject Inconsistent overriding of Interger methods
Date Sun, 19 Aug 2018 13:00:44 GMT
Ladies and gentlemen,

the debate of null-propagation led me to bumping into a wildly inconsistent behaviour when
one overrides Integer methods through the metaclass.

To me, this looks like a bug; even if this mess happens to be an intended behaviour, it is
pretty weird (in this case, is it documented anywhere?)

768 /tmp> <q.groovy                                   
java.lang.Integer.metaClass.byteValue={ -> "OK" }{ o -> "OK" }
println "byteValue works: ${1.byteValue()}"
println "plus does not: ${1+2}"
println "not even: ${}"{ o -> "OK" }
println "Elsewhere plus works: ${[]+1}"
768 /tmp> /usr/local/groovy-3.0.0-alpha-3/bin/groovy q
WARNING: Using incubator modules: jdk.incubator.httpclient
byteValue works: OK
plus does not: 3
not even: 3
Elsewhere plus works: OK
769 /tmp> 

Thanks and all the best,

View raw message