午夜拍鍵驚奇
          子夜 編程 代碼與我同在
          posts - 48,comments - 118,trackbacks - 79

          “Ease of Development”是J2SE 1.5的主要賣點。為此,這一版本加入了七種新的語言特性——Enhanced for Loop、Autoboxing/Auto-Unboxing、Varargs、Static Import、Enumeration、Metadata和Generics。使用這些特性,可以讓編寫出來的程序更簡練、更清晰、更不容易出錯,從而簡化開發的過程。

          Joshua Bloch(《Effective Java》的作者,J2SE 1.5的主要開發人員之一)效仿William Blake(1757-1827,英國詩人)的《Tiger》一詩,為這些特性撰寫了這樣一組詩篇:

          詠Tiger

          Tiger, Tiger burning bright
          Like a geek who works all night
          What new-fangled bit or byte
          Could ease the hacker"s weary plight?

          這一首是總說Tiger中的能使開發變得簡單的各種新語言特性。

          詠Enhanced for Loop

          While Iterators have their uses
          They sometimes strangle us like nooses
          With enhanced-for"s deadly ray
          Iterator"s kept at bay

          這一首單表Enhanced for Loop機制提供了一種更簡單的遍歷數組、Collection和其它實現了java.lang.Iterable接口的對象的方法。

          詠Autoboxing/Auto-Unboxing

          When from the collections ints are drawn
          Wrapper classes make us mourn
          When Tiger comes, we"ll shed no tears
          We"ll autobox them in the ears

          這一首單表Autoboxing機制/Auto-Unboxing提供了一種更簡單的整合兩套不同的類型系統(基本類型和引用類型)的機制。

          詠Varargs

          O joyless nights, o joyless days
          Our programs cluttered with arrays
          With varargs here, we needn"t whine;
          We"ll simply put the args inline

          這一首單表Varargs機制提供了一種更簡單的傳遞個數可變的實參的方法。

          詠Static Import

          And from the constant interface
          We shall inherit no disgrace
          With static import at our side
          Our joy will be unqualified

          這一首單表Static Import機制提供了一種更簡單的訪問靜態成員的機制。

          詠Enumeration

          The int-enum will soon be gone
          Like a foe we"ve known too long.
          With type safe-enum"s mighty power
          Our foe will bother us no more

          這一首單表Enumeration機制提供了一種更簡單的定義“類型安全的枚舉類”的方法。

          詠Metadata

          As for noble metadata
          I"ll have to sing its praises later
          Its uses are so numerous
          To give their due, I"d miss the bus

          這一首單表Metadata機制提供了一種更簡單的定義“機器可讀的說明信息”的機制。

          詠Generics

          To the most despised collections" cast
          We"ll bid a fond farewell at last
          With generics" burning spear
          The need for cast will disappear

          這一首是說用Generics機制,可以免去很多強制類型轉化的步驟的事情。Generics機制還有些其它用法,在這里沒有提到。

          posted on 2005-09-08 16:59 ^ Mustang ^ 閱讀(1210) 評論(0)  編輯  收藏 所屬分類: Java 點滴
          主站蜘蛛池模板: 林州市| 上高县| 仪征市| 阿巴嘎旗| 榕江县| 全椒县| 汝州市| 尼木县| 比如县| 宣武区| 巢湖市| 牙克石市| 达拉特旗| 阜康市| 伽师县| 聂荣县| 海宁市| 五指山市| 漳平市| 古浪县| 东莞市| 奈曼旗| 黑水县| 新河县| 昌都县| 元氏县| 双牌县| 威信县| 保德县| 临江市| 郯城县| 竹溪县| 鲁甸县| 洛隆县| 会泽县| 临泽县| 梁平县| 增城市| 修文县| 松原市| 玛纳斯县|