實現java 眾多API中的一個是一件困難的工作。你必須經常實現許多相互依靠的接口。對新特征的需求促進了最新Java API的創建,投資商們必須不斷的更新他們的實現以跟上時代的需要。當復雜性和持續修改可以理解甚至被看好時, API 版本的不兼容性迫使你為更新的版本保留獨立的代碼庫,從而N次方增加你的受挫等級。本文演示了如何克服接口版本的不兼容性,制作可為多個API版本編譯的代碼庫的進程。
/** Dummy class to allow ConnectionWrapper to implement java.sql.Connection * and still compile under J2SE 1.3 and J2SE 1.4. When compiled * under J2SE 1.3, this class compiles as a placeholder instead of the * missing java.sql.Savepoint (not in J2SE 1.3). When compiled * under J2SE 1.4, this class is ignored and ConnectionWrapper uses the * java.sql.Savepoint that is new in J2SE 1.4. */ public class Savepoint {}
在J2SE 1.4下,我現在可以正確的輸入java.sql.Savepoint。在J2SE 1.3下, Ant 注釋輸入行,這樣我的代碼中引用的 Savepoint正好在同一個軟件包處于