Re: Newbie: cloning a Number
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Wed, 06 Dec 2006 15:42:46 GMT
Daniel Pitts wrote:
Philipp wrote:Andreas Leitgeb wrote:I believe the Number class's primary purpos is to provide a constantPhilipp <sicsicsic@xxxxxxxxxxx> wrote:Yes this is correct.
My application needs some parameters (Number).So, you could just as well use double or long.
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
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.
Unfortunately, they are not required to have a consistent conversion to
BigDecimal. That is the only API type that can exactly represent the
value of any double, any long, any BigInteger, etc., and provides
operations on them.
Patricia
.
- References:
- Re: Newbie: cloning a Number
- From: Daniel Pitts
- Re: Newbie: cloning a Number
- Prev by Date: Re: Giving an application a window icon in a sensible way
- Next by Date: Re: Giving an application a window icon in a sensible way
- Previous by thread: Re: Newbie: cloning a Number
- Next by thread: Re: Singleton Pattern
- Index(es):
Relevant Pages
|