我读过 here如果 Oracle 在 Java 9 中删除 sun.misc.Unsafe
,Spring 和许多其他流行的库将会中断。但是,在 Spring 或 Hibernate 中没有对此类的静态引用。那么,这种说法是真的吗?
顺便说一句,Java 8 中有 64 个对 Unsafe
的引用,但如果 Oracle 删除了该类,他们将更新所有这些类,并且不会影响任何库(除非他们使用 Unsafe
直接就是)。
最佳答案
Mark Reinhold 在 2015 年 JVM 语言峰会上发表了题为 The Secret History and Tragic Fate of sun.misc.Unsafe 的演讲.尽管这些会谈有很多免责声明,但您可以在 10:23 上查看建议的方法。 ,在 JEP260 中有描述.
大体思路是:
- 用更安全、受支持的 API 替换现有功能
- 弃用已被替换的先前存在的
Unsafe
API - 在下一版本中删除已弃用的代码
以下是来自 JEP260 的一些相关文本(取自 2015 年 10 月 20 日):
In JDK 9 we propose to:
Encapsulate all non-critical internal APIs by default: The modules that define them will not export their packages for outside use. (Access to such APIs will be available, as a last resort, via a command-line flag at both compile time and run time, unless those APIs are revised or removed for other reasons.)
Encapsulate critical internal APIs for which supported replacements exist in JDK 8, in the same manner and with the same last-resort workaround. (A supported replacement is one that is either part of the Java SE 8 standard (i.e., in a java.* or javax.* package) or else JDK-specific and annotated with @jdk.Exported (typically in a com.sun.* or jdk.* package).)
Not encapsulate critical internal APIs for which supported replacements do not exist in JDK 8 and, further, deprecate those which have supported replacements in JDK 9 with the intent to encapsulate them, or possibly even remove them, in JDK 10.
...
Critical internal APIs for which replacements are introduced in JDK 9 will be deprecated in JDK 9 and either encapsulated or removed in JDK 10.
关于java - 在 Java 9 中删除 sun.misc.Unsafe 将破坏 Spring、Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31417320/