Java Android中的sun.misc.Unsafe替代方案
我知道,Java Android中的sun.misc.Unsafe替代方案,java,android,Java,Android,我知道,sun.misc.Unsafe(据我所知,这是可以使用的)只在Android上部分实现(该死),但我正在Android上移植,有很多类似的指令: private static sun.misc.Unsafe getUnsafe() { try { Field unsafeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); unsafeField.setAccessible(tru
sun.misc.Unsafe
(据我所知,这是可以使用的)只在Android上部分实现(该死),但我正在Android上移植,有很多类似的指令:
private static sun.misc.Unsafe getUnsafe() {
try {
Field unsafeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
return (sun.misc.Unsafe) unsafeField.get(null);
} catch (SecurityException e) {
throw new RuntimeException("Could not access the sun.misc.Unsafe handle, permission denied by security manager.", e);
} catch (NoSuchFieldException e) {
throw new RuntimeException("The static handle field in sun.misc.Unsafe was not found.");
} catch (IllegalArgumentException e) {
throw new RuntimeException("Bug: Illegal argument reflection access for static field.", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Access to sun.misc.Unsafe is forbidden by the runtime.", e);
} catch (Throwable t) {
throw new RuntimeException("Unclassified error while trying to access the sun.misc.Unsafe handle.", t);
}
}
在编译时生成错误
所以我的问题是:在安卓系统上有没有其他类似的替代方案