commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [math] BigFraction add, subtract returning references rather than new instances
Date Fri, 20 May 2011 23:25:14 GMT
On 20 May 2011 21:04, Phil Steitz <phil.steitz@gmail.com> wrote:
> This code in BigFraction.add looks dangerous to me:
>
>  if (ZERO.equals(fraction)) {
>            return this;
>  }
>
> subtract has similar code and some other methods return the static
> BigFraction.ZERO.
>
> While BigFractions are Immutable, this could cause problems for
> applications that are expecting new instances resulting from
> arithmetic operations.  Can anyone see any reason that this should
> not be changed to consistently create new instances?

Seems to me that an application that depends on getting new instances is broken.

Cf autoboxing which uses valueOf() which may return a cached instance.

> Phil
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message