Re: Newbie: cloning a Number
- From: "Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx>
- Date: 5 Dec 2006 21:13:38 -0800
Philipp wrote:
Andreas Leitgeb wrote:I believe the Number class's primary purpos is to provide a constant
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
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.
.
- Follow-Ups:
- Re: Newbie: cloning a Number
- From: Patricia Shanahan
- Re: Newbie: cloning a Number
- Prev by Date: Re: Newbie: cloning a Number
- Next by Date: how can i modify this program to list the *.java file using FIlenameFilter
- Previous by thread: Re: Newbie: cloning a Number
- Next by thread: Re: Newbie: cloning a Number
- Index(es):
Relevant Pages
|