Class ConstructorConstructor

java.lang.Object
com.google.gson.internal.ConstructorConstructor

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

  • Constructor Details

  • Method Details

    • checkInstantiable

      static String checkInstantiable(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)
      Calls get(TypeToken, boolean), and allows usage of JDK Unsafe.
    • 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(Type type, Class<? super T> rawType)
      Creates constructors for special JDK collection types which do not have a public no-args constructor.
    • newDefaultConstructor

      private static <T> ObjectConstructor<T> newDefaultConstructor(Class<? super T> rawType, ReflectionAccessFilter.FilterResult filterResult)
    • newDefaultImplementationConstructor

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

      private static ObjectConstructor<? extends Collection<?>> newCollectionConstructor(Class<?> rawType)
    • hasStringKeyType

      private static boolean hasStringKeyType(Type mapType)
    • newMapConstructor

      private static ObjectConstructor<? extends Map<?,Object>> newMapConstructor(Type type, Class<?> rawType)
    • newUnsafeAllocator

      private <T> ObjectConstructor<T> newUnsafeAllocator(Class<? super T> rawType)
    • toString

      public String toString()
      Overrides:
      toString in class Object