Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 13th, 2008, 12:52 PM   #11
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: How to compare variable types in Java

Quote:
Originally Posted by pushkarajthorat View Post
You mis-located the change..
} while (((increase < 0) || (increase > 105)) || increase.getClass().getName().equals("java.lang.Integer);
Actually, I understood you just fine. You, however, completely ignored my point.

I really don't think I can make this much clearer.

Scanner.readInt() will either return an int or throw an exception.
titaniumdecoy is offline   Reply With Quote
Old Feb 14th, 2008, 2:01 AM   #12
pushkarajthorat
Java Developer
 
pushkarajthorat's Avatar
 
Join Date: Jun 2006
Location: Solapur, India.
Posts: 22
Rep Power: 0 pushkarajthorat is an unknown quantity at this point
Send a message via Yahoo to pushkarajthorat
Re: How to compare variable types in Java

@itgalary

Yes. It can also be used..
Its better option than <objectname>.class()
because to invoke func. we have to be sure that <objectname> should not be null.
__________________
[Pushkaraj]


Imagination is more important than knowledge – Albert Einstein
pushkarajthorat is offline   Reply With Quote
Old Feb 14th, 2008, 3:48 AM   #13
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: olympia,WA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
Re: How to compare variable types in Java

http://java.sun.com/javase/6/docs/ap...html#nextInt()
do a try catch on it.
__________________
i dont know much about programming but i try to help
mrynit is offline   Reply With Quote
Old Feb 14th, 2008, 5:42 AM   #14
pushkarajthorat
Java Developer
 
pushkarajthorat's Avatar
 
Join Date: Jun 2006
Location: Solapur, India.
Posts: 22
Rep Power: 0 pushkarajthorat is an unknown quantity at this point
Send a message via Yahoo to pushkarajthorat
Re: How to compare variable types in Java

Quote:
Originally Posted by titaniumdecoy View Post
Assuming the increase variable in the code you posted is a Scanner, you can either use the hasNextInt() method to determine if the data waiting to be read can be interpreted as an int value, or catch an exception.
You are assuming that the code is of class Scanner.. On the first look i thought of a object reference instead of premetive type.
__________________
[Pushkaraj]


Imagination is more important than knowledge – Albert Einstein
pushkarajthorat is offline   Reply With Quote
Old Feb 14th, 2008, 1:08 PM   #15
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: How to compare variable types in Java

@pushkarajthorat: First of all, the code you posted which unnecessarily checks that variable is of type Integer contains a logic error: the second logical OR should be a logical AND.

Quote:
Originally Posted by pushkarajthorat View Post
You are assuming that the code is of class Scanner.. On the first look i thought of a object reference instead of premetive type.
You argue that the aforementioned check is necessary if the OP is using an imaginary class which implements a method named readInt() which (oddly enough) returns an Object which might be an Integer or a Double or another non-primitive type. Why would a method with that name return anything other than an int (the most sensible possibility--especially since it is in all likelihood an instance of Scanner) or an Integer? Either possibility would obviate the need for such a check.

Last edited by titaniumdecoy; Feb 14th, 2008 at 1:34 PM.
titaniumdecoy is offline   Reply With Quote
Old Feb 14th, 2008, 11:41 PM   #16
pushkarajthorat
Java Developer
 
pushkarajthorat's Avatar
 
Join Date: Jun 2006
Location: Solapur, India.
Posts: 22
Rep Power: 0 pushkarajthorat is an unknown quantity at this point
Send a message via Yahoo to pushkarajthorat
Re: How to compare variable types in Java

@titaniumdecoy
__________________
[Pushkaraj]


Imagination is more important than knowledge – Albert Einstein
pushkarajthorat is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming with Java: Tutorial ReggaetonKing Java 7 May 20th, 2008 10:58 AM
Special browser in Java (Project) stalefish Java 3 Feb 9th, 2008 4:22 PM
First Java Program duale2005 Java 3 May 22nd, 2006 5:17 PM
Java programmers, game developers, artists, be ware! RPG game team is recruiting! atcomputers.us Paid Job Offers 7 Sep 25th, 2005 7:25 PM
variable problem robert_sun C 1 Apr 12th, 2005 2:10 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC