![]() |
Object to Int
I am doing one of my Java assignments and I need to pass a method an int but I am receiving the data as an Object, is it possible to convert an Object to an int.
I will just demonstrate what I mean because I can't post my actual code. :
public void A(Object o) |
Re: Object to Int
You need to know what the object is an instance of. Assuming it is an Integer, you can call the intValue() method to convert it to an int.
|
Re: Object to Int
test
|
Re: Object to Int
Object is, haha, an object type, while int is a primitive type. You cannot translate objects to ints through direct casts; but if the object is of Integer, you could access and call the member method intValue() which returns the actual integer value being wrapped.
Example: :
public void A(Object o) { |
| All times are GMT -5. The time now is 3:39 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC