有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (3) 个答案

  1. # 1 楼答案

    您不需要直接访问的内部使用包。它们可以在任何版本的Java中更改或删除。您可以找到所有sun的源代码。*和com。太阳。*OpenJDK中的包

  2. # 2 楼答案

    它包含标准Java(EE)API的Oracle参考实现。其中Mojarra(Oracle的参考JSF实现)和Glassfish(Oracle的参考JavaEE实现)使用这个包。最好不要在代码中直接使用这些类,因为这样会使代码与实现紧密耦合。根据java(x)API直接编码使您能够在不更改代码的情况下更改实现(例如,MyFaces代替Mojarra,JBoss代替Glassfish)

    请注意com.sun.*包不应与sun.*包混淆,后者是Oracle JRE背后的内部类,您应该absolutely not在代码中导入/使用它们,因为这会使代码与JRE make/版本紧密耦合。完全不使用sun.*包可以让您在所有其他JRE实现(OpenJDK、GCJ等)上运行代码

  3. # 3 楼答案

    有许多地方使用com.sun包(其中一些在其他答案中提到)。这个答案只是专门针对JavaFX中com.sun的使用JavaFX is a UI library which is part of OpenJDK

    很多JavaFX implementation is in ^{} classes。当JavaFX开源时,JavaFX开发人员就JavaFX中com.sun类的使用提出了following comment

    As always, non-public API (or rather, unsupported API, meaning anything that is not in the javafx namespace such as com.sun.*) cannot be depended on from release to release. But for those of you wondering how things work, there is some very important stuff buried in the unsupported packages, and for those of you wanting to actually hack on OpenJFX, this will be of even greater interest.