java.lang.Object
com.google.gson.internal.UnsafeAllocator
Do sneaky things to allocate objects without invoking their constructors.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
assertInstantiable
(Class<?> c) Asserts that the class is instantiable.(package private) static String
checkInstantiable
(Class<?> c) Check if the class can be instantiated by Unsafe allocator.static UnsafeAllocator
create()
abstract <T> T
newInstance
(Class<T> c)
-
Constructor Details
-
UnsafeAllocator
public UnsafeAllocator()
-
-
Method Details
-
newInstance
- Throws:
Exception
-
checkInstantiable
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
-
assertInstantiable
Asserts that the class is instantiable. This check should have already occurred inConstructorConstructor
; this check here acts as safeguard since trying to use Unsafe for non-instantiable classes might crash the JVM on some devices. -
create
-