java package sun.misc Unsafe 类

单例  不能new 

主要方法 
compareAndSwapObject
public final class Unsafe {
    private static final Unsafe theUnsafe;
    

    private Unsafe() {
    }

    @CallerSensitive
    public static Unsafe getUnsafe() {
        Class caller = Reflection.getCallerClass();
        if (!VM.isSystemDomainLoader(caller.getClassLoader())) {
            throw new SecurityException("Unsafe");
        } else {
            return theUnsafe;
        }
    }

你可能感兴趣的:(杂谈)