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 voidassertInstantiable(Class<?> c) Asserts that the class is instantiable.(package private) static StringcheckInstantiable(Class<?> c) Check if the class can be instantiated by Unsafe allocator.static UnsafeAllocatorcreate()abstract <T> TnewInstance(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-nullexception 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
-