Java Class.isInstance(Object obj)

Syntax

Class.isInstance(Object obj) has the following syntax.

public boolean isInstance(Object obj)

Example

In the following code shows how to use Class.isInstance(Object obj) method.


public class Main {
/*from   w  ww . ja va2  s  .  c  om*/
   public static void main(String[] args) {
     Class cls = Long.class;
        
     Long l = new Long(8);
     Double d = new Double(3.5);
       
     // checking for Long instance
     boolean retval = cls.isInstance(l);
     System.out.println(l + " is Long ? " + retval);

     // checking for Long instance
     retval = cls.isInstance(d);
     System.out.println(d + " is Long ? " + retval);        
   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable