Class.isInstance does what you want.
if (Point.class.isInstance(someObj)){
...
}
Of course, you shouldn’t use it if you could use instanceof
instead, but for reflection scenarios it often comes in handy.
More Related Contents:
- What is the difference between instanceof and Class.isAssignableFrom(…)?
- Avoiding instanceof in Java
- Get generic type of class at runtime
- Can you find all classes in a package using reflection?
- Java Reflection: How to get the name of a variable?
- Gson TypeToken with dynamic ArrayList item type
- Use of “instanceof” in Java [duplicate]
- How to load Classes at runtime from a folder or JAR?
- How to create a generic array in Java?
- Run piece of code contained in a String
- What could cause java.lang.reflect.InvocationTargetException?
- Is it possible to use the instanceof operator in a switch statement?
- How do I read all classes from a Java package in the classpath?
- Printing all variables value from a class
- How to call a superclass method using Java reflection
- Printing debug info on errors with java 8 lambda expressions
- What is the difference between a.getClass() and A.class in Java?
- Instantiating object of type parameter
- How to get the Array Class for a given Class in Java?
- What is the security risk of object reflection?
- Java Reflection: Getting fields and methods in declaration order
- Difference between Loading a class using ClassLoader and Class.forName
- How to disable Java security manager?
- How to get the generic type at runtime?
- Why is reflection slow?
- Using reflection in Java to create a new instance with the reference variable type set to the new instance class name?
- How to invoke a method in java using reflection
- Simple way to get wrapper class type in Java
- Wrong number of arguments error when invoking a method
- Create new object using reflection?