UnSafe类功能强大,可直接操作内存等,具体功能见下图

Java获取UnSafe类

由于JDK并没有开放对UnSafe的获取端口,所以可通过如下方式进行获取

    public static Unsafe getUnSafe() throws NoSuchFieldException, IllegalAccessException {
        Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
        theUnsafe.setAccessible(true);
        return (Unsafe) theUnsafe.get(null);
    }

 

相关文章: