Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2689 > unrolled thread
| Started by | iolamide@lakeheadu.ca |
|---|---|
| First post | 2013-04-24 13:47 -0700 |
| Last post | 2013-04-25 13:19 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.java.help
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | iolamide@lakeheadu.ca |
|---|---|
| Date | 2013-04-24 13:47 -0700 |
| Subject | Re: Casting from Object to int |
| Message-ID | <657a1ab4-18e7-4e7a-957d-dd3da2969b2a@googlegroups.com> |
On Thursday, December 20, 2007 3:44:08 PM UTC+4, gaztedo wrote:
> Hi there!
>
> 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;
> }
>
> Thanks in advance!
[toc] | [next] | [standalone]
| From | iolamide@lakeheadu.ca |
|---|---|
| Date | 2013-04-24 13:50 -0700 |
| Message-ID | <55c30899-f698-492e-94bb-96b4baa21d38@googlegroups.com> |
| In reply to | #2689 |
On Thursday, April 25, 2013 12:47:54 AM UTC+4, iola...@lakeheadu.ca wrote:
> On Thursday, December 20, 2007 3:44:08 PM UTC+4, gaztedo wrote:
>
> > Hi there!
>
> >
>
> > 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;
>
> > }
>
> >
>
> > Thanks in advance!
For you to cast from object to int, i would advice you to use this method which is as follow if the Integer.ParseInt(object.toSring())
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
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2013-04-25 13:19 -0700 |
| Message-ID | <03237363-9eda-4abf-b8ef-a49b529a4ebe@googlegroups.com> |
| In reply to | #2690 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web