Java Number Object

C

calvin.chan.cch

I got a function contain Number Object

public static String test(Number p1) {
}

how could I pass the parameter into it?
Thanks

String a = test( 123.45 );
String a = test( (Number)123.45 );

.... those r not working
 
S

shakah

I got a function contain Number Object

public static String test(Number p1) {

}how could I pass the parameter into it?
Thanks

String a = test( 123.45 );
String a = test( (Number)123.45 );

... those r not working

String a = test(new Float(123.45)) ;

?
 
T

togauravdaga

Hi calvin

Number is Super class of Integer, Float, Long, Double etc. and this
class is abstract class so you need to pass the the object of any
subclass of it.

By keeping the signature of this method with Number parameter , it is
being generalized ie you can pass any number object to this function.

HTH?
Take Care,
Gaurav Daga
 
T

trippy

(e-mail address removed) took the hamburger meat, threw it on the grill,
and I said "Oh Wow"...
Hi calvin

Number is Super class of Integer, Float, Long, Double etc. and this
class is abstract class so you need to pass the the object of any
subclass of it.

By keeping the signature of this method with Number parameter , it is
being generalized ie you can pass any number object to this function.

HTH?
Take Care,
Gaurav Daga

<SSCCE>

public class TestNumber {

public void doIt() {

Number aNum = new Float(123.45);

testNum(aNum);

}

public void testNum(Number n) {

System.out.println(n.toString());

}

public static void main(String[] args) {

TestNumber tn = new TestNumber();
tn.doIt();

}

}

</SSCCE>
--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "Aces High" -- Iron Maiden

"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."

-- Robert Redford "Spy Game"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,270
Messages
2,571,102
Members
48,773
Latest member
Kaybee

Latest Threads

Top