Class UnsafeAllocator


  • public abstract class UnsafeAllocator
    extends java.lang.Object
    Do sneaky things to allocate objects without invoking their constructors.
    • Constructor Detail

      • UnsafeAllocator

        public UnsafeAllocator()
    • Method Detail

      • newInstance

        public abstract <T> T newInstance​(java.lang.Class<T> c)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • 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
      • assertInstantiable

        private static void assertInstantiable​(java.lang.Class<?> c)
        Asserts that the class is instantiable. This check should have already occurred in ConstructorConstructor; this check here acts as safeguard since trying to use Unsafe for non-instantiable classes might crash the JVM on some devices.