InheritanceUtils (Apache Commons Lang 3.17.0 API)
Description: declaration: package: org.apache.commons.lang3.reflect, class: InheritanceUtils

Package org.apache.commons.lang3.reflect

# Class InheritanceUtils

java.lang.Object
org.apache.commons.lang3.reflect.InheritanceUtils

public class InheritanceUtils extends Object
Utility methods focusing on inheritance.

Since:
  3.2

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `InheritanceUtils()`
  Deprecated.
  TODO Make private in 4.0.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `distance(Class<?> child, Class<?> parent)`
  Returns the number of inheritance hops between two classes.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### InheritanceUtils

    @Deprecated public InheritanceUtils()
    Deprecated.
    TODO Make private in 4.0.
    `InheritanceUtils` instances should NOT be constructed in standard programming. Instead, the class should be used as `MethodUtils.getAccessibleMethod(method)`.

    This constructor is `public` to permit tools that require a JavaBean instance to operate.

- ## Method Details

  - ### distance

    public static int distance(Class<?> child, Class<?> parent)
    Returns the number of inheritance hops between two classes.
    Parameters:
      `child` - the child class, may be `null`
      `parent` - the parent class, may be `null`
    Returns:
      the number of generations between the child and parent; 0 if the same class; -1 if the classes are not related as child and parent (includes where either class is null)
    Since:
      3.2