Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2692
| Newsgroups | comp.lang.java.help |
|---|---|
| Date | 2013-04-25 13:19 -0700 |
| References | <476a558a$1_1@filemon1.isp.telecable.es> <657a1ab4-18e7-4e7a-957d-dd3da2969b2a@googlegroups.com> <55c30899-f698-492e-94bb-96b4baa21d38@googlegroups.com> |
| Message-ID | <03237363-9eda-4abf-b8ef-a49b529a4ebe@googlegroups.com> (permalink) |
| Subject | Re: Casting from Object to int |
| From | Lew <lewbloch@gmail.com> |
iola...@lakeheadu.ca wrote:
>iola...@lakeheadu.ca wrote:
>> On Thursday, December 20, 2007 3:44:08 PM UTC+4, gaztedo wrote:
>>> I'm developing a method which receives two Object parameters, and I need
>>> to cast one of them to int. How can I do it?
>>>
>>> public method(Object a, Object b){
>>> this.b = (int)b; // doesn't work!
>>> this.a = a;
>>> }
>
> For you to cast from object to int, i [sic] would advice you to use this method which is as follow
> if the Integer.ParseInt(object.toSring()) [sic]
But of course you have to catch any 'NumberFormatException', and it's really bad design, and
why are you answering a five-year-old thread?
> The string representation of the object is returned by the toString() and the string return value is
> passed as an arguement to the Integer.ParseInt() method.
> Good luck, should you need further clarification, do let me know
Unlikely the OP is still checking on this thread, wouldn't you think?
And they might want to check with someone who gives better advice anyway.
Like, declare the method to take an 'int' in the first place.
--
Lew
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Casting from Object to int iolamide@lakeheadu.ca - 2013-04-24 13:47 -0700
Re: Casting from Object to int iolamide@lakeheadu.ca - 2013-04-24 13:50 -0700
Re: Casting from Object to int Lew <lewbloch@gmail.com> - 2013-04-25 13:19 -0700
csiph-web