Re: Newbie: cloning a Number




Philipp wrote:
Andreas Leitgeb wrote:
Philipp <sicsicsic@xxxxxxxxxxx> wrote:

My application needs some parameters (Number).

So, you could just as well use double or long.

Yes this is correct.
I just thought that this was the whole purpose of a "Number" class. ie
not needing to say if it's actually an integer or a double, but leaving
this to when real calculation is done.

Also my parameters are displayed in JFormattedTextFields which I would
like not to display Integers and Double the same way (with or witout
fraction digits). So keeping this info seemed important to me.

From my C++ background I would have implemented the standard math
operators (+ - * /) on Number such that the polymorphism is used (ie if
Number*Number is actually Integer*Integer: do integer math. If it's
Double*Integer do double math). But this does not seem to be the purpose
of the Number class in Java.
(what's it's purpose actually?)

Best regards
Phil
I believe the Number class's primary purpos is to provide a constant
way to represent numeric values as Objects in a type independant way.
All Number subclasses have intValue(), floatValue(), etc..., so that
you can convert from a Number object to any primative type.

Other than that, most people use a specific Number subclass, rather
than Number itself.

.



Relevant Pages

  • Re: What Math Is Needed for Programming?
    ... Teach you the math. ... But, as others have said, the first purpose may be necessary to solve ... functional programming languages. ... Pythagorean theorem from geometry saved my bacon there. ...
    (comp.lang.java)
  • Re: Tracking of Killer Asteroids Runs Low on Money and Short on Time
    ... Multi-personality disorder ?:-) ... Fred can do math and understands electronics, ... he is effectively able to be wrong on purpose. ...
    (sci.electronics.design)
  • Re: Publication not so important in mathematics
    ... >> I wonder if you misunderstand the purpose of publication. ... >> Which basically is saying that math people believe that it's all ... > But I said the MAIN purpose is to acquaint readers with the material. ...
    (sci.math)
  • Re: Publication not so important in mathematics
    ... >> The main purpose is to acquaint readers with the material. ... > Which basically is saying that math people believe that it's all ... And just as the local paper of Topeka, ...
    (sci.math)
  • Re: Newbie: cloning a Number
    ... I just thought that this was the whole purpose of a "Number" class. ... like not to display Integers and Double the same way (with or witout ... Number*Number is actually Integer*Integer: do integer math. ... All Number subclasses have intValue, floatValue, etc..., so that ...
    (comp.lang.java.programmer)