午夜拍鍵驚奇
          子夜 編程 代碼與我同在
          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 ^ 閱讀(1209) 評論(0)  編輯  收藏 所屬分類: Java 點滴
          主站蜘蛛池模板: 股票| 宁乡县| 庄浪县| 天峨县| 松溪县| 娄底市| 沧源| 车致| 博野县| 阳曲县| 湟中县| 城固县| 楚雄市| 洛南县| 焦作市| 大石桥市| 和硕县| 蓝山县| 迁安市| 峡江县| 手游| 兰西县| 贵阳市| 盘山县| 邹平县| 鹤壁市| 阳谷县| 通江县| 卓尼县| 朔州市| 磴口县| 宣城市| 中江县| 石门县| 云南省| 古蔺县| 如东县| 唐山市| 新营市| 铜川市| 资源县|