Le 21/05/2011 01:25, sebb a écrit :
On 20 May 2011 21:04, Phil Steitz<[email protected]>  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?

Speed and memory. This is especially important for instances that are really used a lot (0, 1 ...) as building them anew a lot of times seems unneeded for immutable instances.


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

I tend to agree here, but there is certainly a reason for such a need. Could you explain why new instances are mandatory ?

Luc


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

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to