Search code examples
javainheritanceobjectextend

How to tell what an object extends externally in java


Hello I need to know if there is a way to find out what an object extends in Java.

public void function(Obj obj)
{
    // ...

Is there a way to find out what obj extends? or if it extends anything?


Solution

  • I assume you mean that you want to find out which class this object is an instance of. In this case you can simply use Object.getClass(). Also you have Class.getSuperclass() at your disposal if you need to find the superclasses of the object class.