Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2692

Re: Casting from Object to int

X-Received by 10.224.75.137 with SMTP id y9mr5419917qaj.3.1366921162310; Thu, 25 Apr 2013 13:19:22 -0700 (PDT)
X-Received by 10.50.101.101 with SMTP id ff5mr13428igb.11.1366921162270; Thu, 25 Apr 2013 13:19:22 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!gp5no3593499qab.0!news-out.google.com!ef9ni16888qab.0!nntp.google.com!gp5no6961432qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.help
Date Thu, 25 Apr 2013 13:19:21 -0700 (PDT)
In-Reply-To <55c30899-f698-492e-94bb-96b4baa21d38@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
NNTP-Posting-Host 69.28.149.29
References <476a558a$1_1@filemon1.isp.telecable.es> <657a1ab4-18e7-4e7a-957d-dd3da2969b2a@googlegroups.com> <55c30899-f698-492e-94bb-96b4baa21d38@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <03237363-9eda-4abf-b8ef-a49b529a4ebe@googlegroups.com> (permalink)
Subject Re: Casting from Object to int
From Lew <lewbloch@gmail.com>
Injection-Date Thu, 25 Apr 2013 20:19:22 +0000
Content-Type text/plain; charset=ISO-8859-1
X-Received-Bytes 2333
Xref csiph.com comp.lang.java.help:2692

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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