Object x = someApi();

if (x instanceof Integer) 

Note that if someApi() returns type Integer the only possibilities of something returned are:

  • an Integer
  • null

In which case you can:

if (x == null) {
    // not an Integer
} else {
    // yes an Integer
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *