Class ReflectionUtils

java.lang.Object
rs.baselib.lang.ReflectionUtils

public class ReflectionUtils
extends java.lang.Object
Reflection utilities.
Since:
1.2.9
Author:
ralph
  • Constructor Summary

    Constructors 
    Constructor Description
    ReflectionUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.Class<?> getClass​(java.lang.reflect.Type type)
    Get the underlying class for a type, or null if the type is a variable type.
    static <T> java.util.List<java.lang.Class<?>> getTypeArguments​(java.lang.Class<T> baseClass, java.lang.Class<? extends T> childClass)
    Get the actual type arguments a child class has used to extend a generic base class.
    static boolean isAbstract​(java.lang.reflect.Member member)
    Returns whether member is declared abstract.
    static boolean isFinal​(java.lang.reflect.Member member)
    Returns whether member is declared final.
    static boolean isInstanceOf​(java.lang.Class<?> inspectedClass, java.lang.String className)
    Replacement for Class.isAssignableFrom(Class) when it cannot be guaranteed that the class is available in classpath at runtime.
    static boolean isInstanceOf​(java.lang.Object o, java.lang.String className)
    Replacement for "instanceof" operator when it cannot be guaranteed that the class is available in classpath at runtime.
    static boolean isNative​(java.lang.reflect.Member member)
    Returns whether member is declared native.
    static boolean isPrivate​(java.lang.reflect.Member member)
    Returns whether member is declared private.
    static boolean isProtected​(java.lang.reflect.Member member)
    Returns whether member is declared protected.
    static boolean isPublic​(java.lang.reflect.Member member)
    Returns whether member is declared public.
    static boolean isStatic​(java.lang.reflect.Member member)
    Returns whether member is declared static.
    static boolean isStrict​(java.lang.reflect.Member member)
    Returns whether member is declared strict.
    static boolean isSynchronized​(java.lang.reflect.Member member)
    Returns whether member is declared synchronized.
    static boolean isTransient​(java.lang.reflect.Member member)
    Returns whether member is declared transient.
    static boolean isVolatile​(java.lang.reflect.Member member)
    Returns whether member is declared volatile.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • isInstanceOf

      public static boolean isInstanceOf​(java.lang.Object o, java.lang.String className)
      Replacement for "instanceof" operator when it cannot be guaranteed that the class is available in classpath at runtime.
      Parameters:
      o - the object to be checked
      className - the complete class name
      Returns:
      when the object is of that class
    • isInstanceOf

      public static boolean isInstanceOf​(java.lang.Class<?> inspectedClass, java.lang.String className)
      Replacement for Class.isAssignableFrom(Class) when it cannot be guaranteed that the class is available in classpath at runtime.
      Parameters:
      inspectedClass - the class to be checked
      className - the complete class name that should be implemented or a superclass of the inspected class
      Returns:
      when the inspected class implements or derived from the class with given name
    • getClass

      public static java.lang.Class<?> getClass​(java.lang.reflect.Type type)
      Get the underlying class for a type, or null if the type is a variable type.
      Parameters:
      type - the type
      Returns:
      the underlying class
    • getTypeArguments

      public static <T> java.util.List<java.lang.Class<?>> getTypeArguments​(java.lang.Class<T> baseClass, java.lang.Class<? extends T> childClass)
      Get the actual type arguments a child class has used to extend a generic base class.
      Type Parameters:
      T - type of base class
      Parameters:
      baseClass - the base class
      childClass - the child class
      Returns:
      a list of the raw classes for the actual type arguments.
    • isPublic

      public static boolean isPublic​(java.lang.reflect.Member member)
      Returns whether member is declared public.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared public
    • isProtected

      public static boolean isProtected​(java.lang.reflect.Member member)
      Returns whether member is declared protected.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared protected
    • isPrivate

      public static boolean isPrivate​(java.lang.reflect.Member member)
      Returns whether member is declared private.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared private
    • isStatic

      public static boolean isStatic​(java.lang.reflect.Member member)
      Returns whether member is declared static.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared static
    • isFinal

      public static boolean isFinal​(java.lang.reflect.Member member)
      Returns whether member is declared final.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared final
    • isVolatile

      public static boolean isVolatile​(java.lang.reflect.Member member)
      Returns whether member is declared volatile.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared volatile
    • isSynchronized

      public static boolean isSynchronized​(java.lang.reflect.Member member)
      Returns whether member is declared synchronized.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared synchronized
    • isAbstract

      public static boolean isAbstract​(java.lang.reflect.Member member)
      Returns whether member is declared abstract.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared abstract
    • isNative

      public static boolean isNative​(java.lang.reflect.Member member)
      Returns whether member is declared native.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared native
    • isTransient

      public static boolean isTransient​(java.lang.reflect.Member member)
      Returns whether member is declared transient.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared transient
    • isStrict

      public static boolean isStrict​(java.lang.reflect.Member member)
      Returns whether member is declared strict.
      Parameters:
      member - member to be inspected
      Returns:
      true when member was declared strict