Class Reflect


  • public final class Reflect
    extends Object
    This class assembles some reflection methods. Most exceptions are caught and replaced by a null value.
    Author:
    BaseX Team 2005-23, BSD License, Christian Gruen
    • Method Detail

      • available

        public static boolean available​(String pattern,
                                        Object... ext)
        Checks if the class specified by the pattern is available.
        Parameters:
        pattern - class pattern
        ext - optional extension
        Returns:
        result of check
      • find

        public static Class<?> find​(String name)
        Caches and returns a reference to the specified class.
        Parameters:
        name - fully qualified class name
        Returns:
        reference, or null if the class is not found
      • forName

        public static Class<?> forName​(String name)
                                throws ClassNotFoundException
        Caches and returns a reference to the specified class, or throws an exception.
        Parameters:
        name - fully qualified class name
        Returns:
        class reference
        Throws:
        ClassNotFoundException - any exception or error
      • field

        public static Field field​(Class<?> clazz,
                                  String name)
        Caches and returns a reference to the specified field or null.
        Parameters:
        clazz - class to search for the constructor
        name - field name
        Returns:
        reference or null if the field is not found
      • find

        public static Class<?> find​(String pattern,
                                    Object... ext)
        Caches and returns a reference to the class specified by the pattern, or null.
        Parameters:
        pattern - class pattern
        ext - optional extension
        Returns:
        reference or null if the class is not found
      • find

        public static <O> Constructor<O> find​(Class<O> clazz,
                                              Class<?>... types)
        Caches and returns a constructor by parameter types.
        Type Parameters:
        O - class type
        Parameters:
        clazz - class to search for the constructor
        types - constructor parameters
        Returns:
        constructor, or null if the constructor is not found
      • method

        public static Method method​(Class<?> clazz,
                                    String name,
                                    Class<?>... types)
        Finds a public, protected or private method by name and parameter types.
        Parameters:
        clazz - class to search for the method
        name - method name
        types - method parameters
        Returns:
        method, or null if the method is not found
      • get

        public static <O> O get​(Class<O> clazz)
        Returns a class instance.
        Type Parameters:
        O - type
        Parameters:
        clazz - class
        Returns:
        instance or null
      • get

        public static <O> O get​(Constructor<O> clazz,
                                Object... args)
        Returns a class instance or null.
        Type Parameters:
        O - class type
        Parameters:
        clazz - class
        args - arguments
        Returns:
        instance or null
      • invoke

        public static Object invoke​(Method method,
                                    Object object,
                                    Object... args)
        Invokes the specified method.
        Parameters:
        method - method to run
        object - object (null for static methods)
        args - arguments
        Returns:
        result of method call or null
      • get

        public static Object get​(Field field,
                                 Object object)
        Returns the value of a field.
        Parameters:
        field - field to access
        object - object (null for static methods)
        Returns:
        value of field