com.sun.awt package usage

前端 未结 3 728
走了就别回头了
走了就别回头了 2021-01-05 14:21

I found a java code and want to use it in my project. It contains these imports that my JDK does not have :

import com.sun.awt.AWTU         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 14:58

    You should not use any com.sun packages except as a last resort. These are considered to be implementation details, and they are not part of the JDK API. They can change arbitrarily between versions, so they can cause problems when you try to upgrade JDK versions.

    The com.sun classes are almost always wrapped by "official" classes - you should use those instead. You can use these in a last resort situation, but they are already part of the JDK download, so there should be no extra downloading necessary.

    EDIT: Looks like you're right, you do need to download some extra jars. The JNA jar is available on maven central (http://mvnrepository.com/artifact/com.sun.jna/jna/3.0.9). Especially if this is a code snippet you found, I would highly advise against using com.sun packages directly.

提交回复
热议问题