Class OptionalMethod


  • @Internal
    public final class OptionalMethod
    extends java.lang.Object
    Helper class to handle reflexive loading and invocation of methods which may be absent.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.reflect.Method cachedMethod  
    • Constructor Summary

      Constructors 
      Constructor Description
      OptionalMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... methodParams)
      Instantiates a new OptionalMethod.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static <T> T checkNotNull​(T reference)  
      private static java.lang.reflect.Method initializeMethod​(java.lang.Class<?> clazz, java.lang.String methodName, java.lang.Class<?>... methodParams)  
      java.lang.Object invoke​(java.lang.Object target, java.lang.Object... args)  
      java.lang.Object invokeStatic​(java.lang.Object... args)  
      • Methods inherited from class java.lang.Object

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

      • cachedMethod

        private final java.lang.reflect.Method cachedMethod
    • Constructor Detail

      • OptionalMethod

        public OptionalMethod​(java.lang.Class<?> clazz,
                              java.lang.String methodName,
                              java.lang.Class<?>... methodParams)
        Instantiates a new OptionalMethod.

        Does not throw any exceptions if the class or method can't be loaded, or if any parameter classes are null and instead behaves as a no-op, always returning null.

        Parameters:
        clazz - the Class to search for methods on
        methodName - the name of the Method on clazz
        methodParams - list of Classes of the Method's parameters
        Throws:
        java.lang.NullPointerException - if the method name is null
    • Method Detail

      • initializeMethod

        private static java.lang.reflect.Method initializeMethod​(java.lang.Class<?> clazz,
                                                                 java.lang.String methodName,
                                                                 java.lang.Class<?>... methodParams)
      • invokeStatic

        public java.lang.Object invokeStatic​(java.lang.Object... args)
      • invoke

        public java.lang.Object invoke​(java.lang.Object target,
                                       java.lang.Object... args)
      • checkNotNull

        private static <T> T checkNotNull​(T reference)