![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Expert Programmer
|
Re: How to compare variable types in Java
Quote:
I really don't think I can make this much clearer. Scanner.readInt() will either return an int or throw an exception. |
|
|
|
|
|
|
#12 |
|
Java Developer
|
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 |
|
|
|
|
|
#13 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#14 |
|
Java Developer
|
Re: How to compare variable types in Java
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 |
|
|
|
|
|
#15 | |
|
Expert Programmer
|
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:
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. |
|
|
|
|
|
|
#16 |
|
Java Developer
|
Re: How to compare variable types in Java
@titaniumdecoy
![]()
__________________
[Pushkaraj] Imagination is more important than knowledge – Albert Einstein |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |