Bug Id: 4032278
Synopsis: Math operators ought to work on subclasses of Number
State: Closed, will not be fixed
Description:
Especially with the introduction of the BigInteger and BigDecimal classes,
it seems a shame that one can't write code like this:
Integer x = new Integer (10);
Double y = new Double (3);
Number z = x + y;
Assuming the compiler statically knows that something is a Number, it ought
to be able to translate +, -, <, etc. The one weirdness is that "==" means
both "mathematical equality" and "same object". In the case of Number ==
Number, it would translate into the method call, but you could force the
"same object" test by casting one or the other argument to Object.
Thanks for listening.
Dan Bornstein
Workaround:
Use the methods and have uglier code. Just try doing complex
numerical algorithms that way and see what I mean.
February 13, 1997
The Java Rants
Copyright © 1997-2000
Dan Bornstein, all rights
reserved.