Class ConstructorConstructor


  • public final class ConstructorConstructor
    extends java.lang.Object
    Returns a function that can construct an instance of a requested type.
    • Field Detail

      • instanceCreators

        private final java.util.Map<java.lang.reflect.Type,​InstanceCreator<?>> instanceCreators
      • useJdkUnsafe

        private final boolean useJdkUnsafe
    • Constructor Detail

      • ConstructorConstructor

        public ConstructorConstructor​(java.util.Map<java.lang.reflect.Type,​InstanceCreator<?>> instanceCreators,
                                      boolean useJdkUnsafe,
                                      java.util.List<ReflectionAccessFilter> reflectionFilters)
    • Method Detail

      • checkInstantiable

        static java.lang.String checkInstantiable​(java.lang.Class<?> c)
        Check if the class can be instantiated by Unsafe allocator. If the instance has interface or abstract modifiers return an exception message.
        Parameters:
        c - instance of the class to be checked
        Returns:
        if instantiable null, else a non-null exception message
      • get

        public <T> ObjectConstructor<T> get​(TypeToken<T> typeToken,
                                            boolean allowUnsafe)
        Retrieves an object constructor for the given type.
        Parameters:
        typeToken - type for which a constructor should be retrieved
        allowUnsafe - whether to allow usage of JDK Unsafe; has no effect if useJdkUnsafe is false
      • newSpecialCollectionConstructor

        private static <T> ObjectConstructor<T> newSpecialCollectionConstructor​(java.lang.reflect.Type type,
                                                                                java.lang.Class<? super T> rawType)
        Creates constructors for special JDK collection types which do not have a public no-args constructor.
      • newDefaultImplementationConstructor

        private static <T> ObjectConstructor<T> newDefaultImplementationConstructor​(java.lang.reflect.Type type,
                                                                                    java.lang.Class<? super T> rawType)
        Constructors for common interface types like Map and List and their subtypes.
      • newCollectionConstructor

        private static ObjectConstructor<? extends java.util.Collection<? extends java.lang.Object>> newCollectionConstructor​(java.lang.Class<?> rawType)
      • hasStringKeyType

        private static boolean hasStringKeyType​(java.lang.reflect.Type mapType)
      • newMapConstructor

        private static ObjectConstructor<? extends java.util.Map<? extends java.lang.Object,​java.lang.Object>> newMapConstructor​(java.lang.reflect.Type type,
                                                                                                                                       java.lang.Class<?> rawType)
      • newUnsafeAllocator

        private <T> ObjectConstructor<T> newUnsafeAllocator​(java.lang.Class<? super T> rawType)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object