Question: Is there a way to use instanceof based on the passed argument of a method? Example

```
doSomething(myClass.class); /* I would like to call this also with other classes */

public void doSomething(/*generic parameter that accepts all classes, not just myClass */) {
  if (myObject instanceOf /* the generic parameter */ == true) {...}
}

```

sometimes I'll call the method using myClass.class but other times I would like to call it using someOtherClass.class - I don't want to change the if condition though. Is that possible? If so, how? :)

Thanks

Answer: 
You're looking for the [`Class.isInstance()` method](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#isInstance(java.lang.Object)).

```
public void doSomething(Class<?> c, Object myObject) {
    if (c.isInstance(myObject)) {...}
}

```
This is the way to do it, as far as I know:

```
public static <T> boolean doInstanceOf(Object object,Class<T> clz) {
        return clz.isInstance(object);
    }

```

Usage:

```
System.out.println(doInstanceOf(myObject,MyClass.class));

```