wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes From object to int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "From object to int" Watch "From object to int" New topic
Author

From object to int

L�szl� Kov�cs
Greenhorn

Joined: Jun 18, 2005
Posts: 17
On a couple of occasions I have had data returned in the form of an object that I need to cast into an int. I would like to know a better way to do it than what I have currently:



Disclaimer: The above post may or may not reflect reality as seen by other people.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
just a guess:
why not making getValue() return an int, including Integer.parseInt() in that method?


java amateur
L�szl� Kov�cs
Greenhorn

Joined: Jun 18, 2005
Posts: 17
I should probably have mentioned that the object is being returned by a JSpinner - since I didn't make it, I can't very easily have it return a different type.
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Laszlo,

I don't see too much that you could change with your code - I suppose you could cut it back by a line -



Regards,
JD
L�szl� Kov�cs
Greenhorn

Joined: Jun 18, 2005
Posts: 17
Thanks JD.
Ravi Shankar R
Greenhorn

Joined: Jan 05, 2005
Posts: 7
Object oValue = mySpinner.getValue(); // getValue() returns an object

// String sValue = oValue.toString(); Eliminate the conversion of an object to String

int iValue = ((Integer)oValue).intValue();

thus, this would give u the same result unless u r sure that the object returned is of Integer type



Cheers,
Ravi
[ July 06, 2005: Message edited by: Ravi Shankar R ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: From object to int
 
Similar Threads
Correct implementation?? :confused:
Incompatible types
equals() method
how to upload files to server using JSP ?
hashcode question