Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

a problem in transfer a int to Object

Thread view: 
fAnSKyer - 30 Oct 2006 22:35 GMT
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.
John Gordon - 30 Oct 2006 23:09 GMT
> 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);

Signature

John Gordon            "It's certainly uncontaminated by cheese."
gordon@panix.com

jartur - 31 Oct 2006 00:27 GMT
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.
Mike  Schilling - 01 Nov 2006 04:12 GMT
>> here is the problem
>> I have an Object[] args[];
[quoted text clipped - 10 lines]
>
>  args[0] = new Integer(refer);

Or, in 1.5, simply

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.