groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ocs@ocs" <...@ocs.cz>
Subject Re: Inconsistent overriding of Interger methods
Date Mon, 20 Aug 2018 15:55:55 GMT
Eric,

I fear not:

===
776 /tmp> /usr/local/groovy-3.0.0-alpha-3/bin/groovy -indy q             
WARNING: Using incubator modules: jdk.incubator.httpclient
byteValue works: OK
plus does not: 3
not even: 3
Elsewhere plus works: OK
777 /tmp> /usr/local/groovy-3.0.0-alpha-3/bin/groovy -disable=int q 
WARNING: Using incubator modules: jdk.incubator.httpclient
byteValue works: OK
plus does not: 3
not even: 3
Elsewhere plus works: OK
778 /tmp> /usr/local/groovy-3.0.0-alpha-3/bin/groovy -disable=all q
WARNING: Using incubator modules: jdk.incubator.httpclient
byteValue works: OK
plus does not: 3
not even: 3
Elsewhere plus works: OK
779 /tmp> 
===

Thanks and all the best,
OC

> On 20 Aug 2018, at 4:19 PM, Milles, Eric (TR Technology & Ops) <eric.milles@thomsonreuters.com>
wrote:
> 
> You may want to disable the int optimization (on by default; off for indy).  I think
then primitives would get converted to wrappers and MOP would be available consistently.
> 
> 
> From: mg <mgbiz@arscreat.com>
> Sent: Monday, August 20, 2018 7:17 AM
> To: dev@groovy.apache.org
> Subject: Re: Inconsistent overriding of Interger methods
>  
> Without having looked at the implementation: Wouldn't "performance" be a plausible explanation
why these cases can't be moped up... ?
> 
> -------- Urspr√ľngliche Nachricht --------
> Von: Paul King <paulk@asert.com.au>
> Datum: 20.08.18 02:59 (GMT+01:00)
> An: dev@groovy.apache.org
> Betreff: Re: Inconsistent overriding of Interger methods
> 
> It appears to be most (all?) primitive/wrapper types not just Integer.
> 
> On Sun, Aug 19, 2018 at 11:00 PM ocs@ocs <ocs@ocs.cz <mailto:ocs@ocs.cz>>
wrote:
> 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" }
> java.lang.Integer.metaClass.plus={ o -> "OK" }
> println "byteValue works: ${1.byteValue()}"
> println "plus does not: ${1+2}"
> println "not even: ${1.plus(2)}"
> ArrayList.metaClass.plus={ 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,
> OC
> 


Mime
View raw message