JavaJava9 中的 LangAccess 和 SharedSecrets

JavaLangAccess and SharedSecrets in Java 9

sun.misc 包中的 SharedSecretsJavaLangAccess 类 似乎已在 Java 9 中删除。

Java 9 中是否有这些 类 提供的功能的替代品?

以上类都打包在jdk.internal.misc包中。

您可以尝试访问它们的一种方法是使用选项

--add-exports <source-module>/<package>=<target-module>(,<target-module>)*

您的用例为:

--add-exports java.base/jdk.internal.misc=your.module

注意:- 来自JEP-261:Module System的免责声明-

The --add-exports and --add-opens options must be used with great care. You can use them to gain access to an internal API of a library module, or even of the JDK itself, but you do so at your own risk: If that internal API is changed or removed then your library or application will fail.

根据Bug#JDK-8137056

In preparation for JEP 160, SharedSecrets and friend interfaces should be moved out of 'sun.misc' and located in a truly private package

现在可以在 jdk.internal.misc

购买

Move SharedSecrets and friends to jdk.internal.misc