It is a bad practice to use Sun's proprietary Java classes?

前端 未结 7 1742
孤独总比滥情好
孤独总比滥情好 2020-11-22 08:59

The compiler display warnings if you use Sun\'s proprietary Java classes. I\'m of the opinion that it\'s generally a bad idea to use these classes. I read this somewhere. Ho

7条回答
  •  伪装坚强ぢ
    2020-11-22 09:35

    The JDK 6 Documentation includes a link titled Note About sun.* Packages. This is a document from the Java 1.2 docs, so references to sun.* should be treated as if they said com.sun.*

    The most important points from it are:

    The classes that Sun includes with the Java 2 SDK, Standard Edition, fall into package groups java.*, javax.*, org.* and sun.*. All but the sun.* packages are a standard part of the Java platform and will be supported into the future. In general, packages such as sun.*, that are outside of the Java platform, can be different across OS platforms (Solaris, Windows, Linux, Macintosh, etc.) and can change at any time without notice with SDK versions (1.2, 1.2.1, 1.2.3, etc). Programs that contain direct calls to the sun.* packages are not 100% Pure Java.

    and

    Each company that implements the Java platform will do so in their own private way. The classes in sun.* are present in the SDK to support the Sun implementation of the Java platform: the sun.* classes are what make the Java platform classes work "under the covers" for the Sun Java 2 SDK. These classes will not in general be present on another vendor's Java platform. If your Java program asks for a class "sun.package.Foo" by name, it may fail with ClassNotFoundError, and you will have lost a major advantage of developing in Java.

提交回复
热议问题