Difference between sun.* vs com.sun.*

Sagar :

I have recently migrated from Java 8 to Java 11. for jax.ws

I had to add following external dependency to my pom.xml as it's no longer available in Java 11. However, I came across some argument that com.sun.* package classes should not be used and should be avoided if possible. So is it sun.* or com.sun.*? If latter is true as well, what would be the best possible replacement for this?

One more thing, this dependency is not directly used by my code but it's referred by one of my other dependencies.

    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.10</version>
    </dependency>
Andy Guibert :

Some com.sun.* classes are actual external API and may be used. The key is to check the official Javadoc to see if the classes you want to use are listed as API, and not marked @Deprecated or anything of that sort.

Here is the official javadoc page to check at: https://docs.oracle.com/en/java/javase/11/docs/api/index.html

In general, sun.* API refers to some of the oldest Java APIs (such as sun.misc.Unsafe) which predate the reverse-DNS package naming convention. Most of the original sun.* APIs have either been removed, promoted to official javax.* API, or renamed to the more proper com.sun.* domain.

There is nothing inherently wrong with using com.sun.* APIs, provided the API is not a JDK internal or marked for deprecation/removal.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77174&siteId=1