Java資格認(rèn)證:JDK1.4與JDK1.6的區(qū)別
在 Linux 下用 jdk 1.6 寫了個(gè)程序,編譯打包后,一切正常,拿到 win 下,同樣是 1.6 的jdk,居然說(shuō)什么不兼容的編譯類型,非法的 magic number.
只好在 Linux下用 jdk 1.4.2 這個(gè)經(jīng)典的版本重新編譯一下,結(jié)果就發(fā)現(xiàn)了下面兩個(gè)不同:1. 在 1.4.2 中, assert 是 keyword ,不可以 assert (boolean expression):(String) 這樣來(lái)用,考試.大提示在 1.6 中是可以的。
在 1.4.2 下編譯時(shí),會(huì)給出warning: as of release 1.4, assert is a keyword, and may not be used as an identifier,并且會(huì)報(bào)錯(cuò),說(shuō)是分號(hào)的錯(cuò)誤(其實(shí)是編譯器把 assert 當(dāng)作 identifier 來(lái)處理報(bào)的錯(cuò))。
2. 在 1.4.2 中,不可以如下這樣來(lái) override clone() 方法
public NewClass clone(){
...
return NewClass;
}
這在 1.6 中是允許的,也是方便的。
在 1.4.2 中只能
public Object clone(){
...
return ...;
}
于是就有了 N 多的強(qiáng)制類型轉(zhuǎn)換。
【編輯推薦】