Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Java instanceof question?

is there a way to check that an object is an integer?

say,

int a=0;

if ( a instanceof int) <---i get an error right here

can't find how what to define an integer when comparing objects

2 Answers

Relevance
  • Chris
    Lv 7
    7 years ago

    The problem is that "a" isn't an Object, it's not a reference. Therefore you can't apply instanceof.

    However, this is a non-problem. You are the programmer, so you know the datatype. Could you give an example where you would actually need this?

  • 7 years ago

    Trying to see if an input is valid rather than using try/catch blocks

Still have questions? Get your answers by asking now.