Class Reflector


  • public class Reflector
    extends java.lang.Object
    Provides accessor objects for efficiently calling otherwise inaccessible (non-public) methods.

    This is orders of magnitude faster than using reflection directly.

    For example, to access a private method on some class Foo, declare an accessor interface:

     class Foo {
       private String getName() { ... }
     }
    
     @ForType(Foo.class)
     interface _Foo_ {
       String getName();
     }
    
     reflector(_Foo_.class, new Foo()).getName();
     
    • Constructor Summary

      Constructors 
      Constructor Description
      Reflector()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T reflector​(java.lang.Class<T> iClass)
      Returns an object which provides accessors for invoking otherwise inaccessible static methods and fields.
      static <T> T reflector​(java.lang.Class<T> iClass, java.lang.Object target)
      Returns an object which provides accessors for invoking otherwise inaccessible methods and fields.
      • Methods inherited from class java.lang.Object

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

      • Reflector

        public Reflector()
    • Method Detail

      • reflector

        public static <T> T reflector​(java.lang.Class<T> iClass)
        Returns an object which provides accessors for invoking otherwise inaccessible static methods and fields.
        Parameters:
        iClass - an interface with methods matching private methods on the target
      • reflector

        public static <T> T reflector​(java.lang.Class<T> iClass,
                                      java.lang.Object target)
        Returns an object which provides accessors for invoking otherwise inaccessible methods and fields.
        Parameters:
        iClass - an interface with methods matching private methods on the target
        target - the target object