Class ClassTool

java.lang.Object
com.xxl.tool.core.ClassTool

public class ClassTool extends Object
Class Tool
Author:
xuxueli 2024-01-21 05:03:10
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Method
    getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes)
    Determine whether the given class has a public method with the given signature, and return it if available (else return null).
    static boolean
    isAssignable(Class<?> superType, Class<?> subType)
    Check if the super-type may be assigned to the sub-type Considers primitive wrapper classes as assignable to the corresponding primitive types.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ClassTool

      public ClassTool()
  • Method Details

    • isAssignable

      public static boolean isAssignable(Class<?> superType, Class<?> subType)
      Check if the super-type may be assigned to the sub-type Considers primitive wrapper classes as assignable to the corresponding primitive types.
      Parameters:
      superType - the target type (left-hand side (LHS) type)
      subType - the value type (right-hand side (RHS) type) that should be assigned to the target type
      Returns:
      true if rhsType is assignable to lhsType
    • getMethod

      public static Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes)
      Determine whether the given class has a public method with the given signature, and return it if available (else return null).

      In case of any signature specified, only returns the method if there is a unique candidate, i.e. a single public method with the specified name.

      Essentially translates NoSuchMethodException to null.

      Parameters:
      clazz - the clazz to analyze
      methodName - the name of the method
      paramTypes - the parameter types of the method (can be null to indicate any signature)
      Returns:
      the method, or null if not found