Class ReflectionHelper


  • public class ReflectionHelper
    extends java.lang.Object
    Static Helper methods for instantiating objects from reflection.
    Author:
    muzquiano
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object invoke​(java.lang.Object obj, java.lang.String method, java.lang.Class[] argTypes, java.lang.Object[] args)
      Invokes a method on the given object by passing the given arguments into the method.
      static java.lang.Object newObject​(java.lang.String className)
      Constructs a new object for the given class name.
      static java.lang.Object newObject​(java.lang.String className, java.lang.Class[] argTypes, java.lang.Object[] args)
      Constructs a new object for the given class name and with the given arguments.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newObject

        public static java.lang.Object newObject​(java.lang.String className)
        Constructs a new object for the given class name. The construction takes no arguments. If an exception occurs during construction, null is returned. All exceptions are written to the Log instance for this class.
        Parameters:
        className - String
        Returns:
        Object
      • newObject

        public static java.lang.Object newObject​(java.lang.String className,
                                                 java.lang.Class[] argTypes,
                                                 java.lang.Object[] args)
        Constructs a new object for the given class name and with the given arguments. The arguments must be specified in terms of their Class[] types and their Object[] values. Example: String s = newObject("java.lang.String", new Class[] { String.class}, new String[] { "test"}); is equivalent to: String s = new String("test"); If an exception occurs during construction, null is returned. All exceptions are written to the Log instance for this class.
        Parameters:
        className - String
        argTypes - Class[]
        args - Object[]
        Returns:
        Object
      • invoke

        public static java.lang.Object invoke​(java.lang.Object obj,
                                              java.lang.String method,
                                              java.lang.Class[] argTypes,
                                              java.lang.Object[] args)
        Invokes a method on the given object by passing the given arguments into the method.
        Parameters:
        obj - Object
        method - String
        argTypes - Class[]
        args - Object[]
        Returns:
        Object