Why is sun.misc discouraged for use?

2019-07-13 11:40发布

问题:

I've been using the BASE64Encoder and BASE64Decoder in sun.misc; I'm using Eclipse and had to turn to warnings since the access is restricted to it by default.

The classes works perfectly, but during my work with this I've read plenty of places that one should not use sun.misc at all but no one states a proper reason.

Should I stay away from sun.misc and why?

回答1:

There is no promise to continue support for these classes; they may be removed from the JDK without warning at any release.

Also, not all JDKs have these classes, so your code may not run on all platforms, which goes against the intention of java's "compile once, run anywhere" philosophy.