java.lang.Object
nl.jqno.equalsverifier.internal.reflection.ClassProbe<T>

public final class ClassProbe<T> extends Object
Provides read-only reflective access to a class.
  • Field Details

    • type

      private final Class<T> type
  • Constructor Details

    • ClassProbe

      private ClassProbe(Class<T> type)
      Private constructor. Call of(Class) instead.
  • Method Details

    • of

      public static <T> ClassProbe<T> of(Class<T> type)
      Factory method.
      Type Parameters:
      T - The class on which ClassProbe operates.
      Parameters:
      type - The class on which ClassProbe operates.
      Returns:
      A ClassProbe for T.
    • getType

      public Class<T> getType()
      Returns the class on which ClassProbe operates.
      Returns:
      The class on which ClassProbe operates.
    • isRecord

      public boolean isRecord()
      Determines whether T is a Java Record.
      Returns:
      true if T is a Java Record.
    • isSealed

      public boolean isSealed()
      Determines whether T is a sealed class.
      Returns:
      true if T is a sealed class
    • isAbstract

      public boolean isAbstract()
      Determines whether T is abstract.
      Returns:
      true if T is abstract.
    • isEmptyOrSingleValueEnum

      public boolean isEmptyOrSingleValueEnum()
      Returns whether T is a single-value enum.
      Returns:
      Whether T is an enum with a single value.
    • declaresEquals

      public boolean declaresEquals()
      Determines whether T has an equals method.
      Returns:
      True if T has an equals method.
    • declaresHashCode

      public boolean declaresHashCode()
      Determines whether T has a hashCode method.
      Returns:
      True if T has a hashCode method.
    • hasMethod

      public boolean hasMethod(String name)
      Determines whether T has a method with the given name and parameters.
      Parameters:
      name - The name of the method we're looking for.
      Returns:
      True if T has a method with the given name and parameters.
    • declaresMethod

      private static boolean declaresMethod(Class<?> type, String name, Class<?>... parameterTypes)
    • isEqualsAbstract

      public boolean isEqualsAbstract()
      Determines whether T's equals method is abstract.
      Returns:
      True if T's equals method is abstract.
    • isHashCodeAbstract

      public boolean isHashCodeAbstract()
      Determines whether T's hashCode method is abstract.
      Returns:
      True if T's hashCode method is abstract.
    • isMethodAbstract

      private boolean isMethodAbstract(String name, Class<?>... parameterTypes)
    • isEqualsInheritedFromObject

      public boolean isEqualsInheritedFromObject()
      Determines whether T's equals method is inherited from Object.
      Returns:
      true if T's equals method is inherited from Object; false if it is overridden in T or in any of its superclasses (except Object).
    • findField

      public Optional<Field> findField(String name)
      Finds a field (no matter its accessibility) in T or its superclasses.
      Parameters:
      name - The name of the field that should be found.
      Returns:
      The field wrapped in an Optional, or an empty Optional if the field could not be found.
    • getField

      private static Field getField(Class<?> type, String name)
    • isMethodFinal

      public boolean isMethodFinal(String methodName, Class<?>... parameterTypes)
      Determines whether the given method in T is final.
      Parameters:
      methodName - The name of the method in T.
      parameterTypes - The types of the method's parameters, to determine the right overload.
      Returns:
      True if the given method in T is final, false if it's not final or if it doesn't exist.
    • findMethod

      private Optional<Method> findMethod(String name, Class<?>... parameterTypes)
    • getMethod

      private static Method getMethod(Class<?> type, String name, Class<?>... parameterTypes)
    • findConstructor

      public Optional<Constructor<T>> findConstructor(Class<?>[] params)
      Finds a constructor (no matter its accessibility) in T or its superclasses.
      Parameters:
      params - The types of the parameters of the constructor that should be found.
      Returns:
      The field wrapped in an Optional, or an empty Optional if the field could not be found.
    • getConstructor

      private static <T> Constructor<T> getConstructor(Class<T> type, Class<?>[] params)
    • getSuperProbe

      public ClassProbe<? super T> getSuperProbe()
      Returns a probe for T's superclass.
      Returns:
      A probe for T's superclass.