a problem in transfer a int to Object

F

fAnSKyer

here is the problem
I have an Object[] args[];

I want use this array args to transfer the values.
For example args[0] is a int; args[1] is a string.

The problem is I can't change a int to string, I use this way

int refer=1
args[0]= (Object) refer;

but it doesn't work

HELP

Thanks a lot
fAnS.
 
J

jartur

Uh-huh. The primitives are not objects, so they don't inherit from
Object thus you can't do that cast. Use primitive's wrappers.
 
M

Mike Schilling

John Gordon said:
In <[email protected]> "fAnSKyer"
here is the problem
I have an Object[] args[];
I want use this array args to transfer the values.
For example args[0] is a int; args[1] is a string.
The problem is I can't change a int to string, I use this way
int refer=1
args[0]= (Object) refer;

You can't cast an int to an Object. Do this instead:

args[0] = new Integer(refer);

Or, in 1.5, simply

args[0] = i; // will generate the same code as args[0] =
Integer.valueOf(refer);
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top