gr8vyguy@Blogjava

          Groovy讀書筆記3

          Chapter 04 The collective Groovy datatypes

          Groovy support collection types: ranges, lists and maps.

          how and what

              language expressiveness, 語言的表達能力
                    how much does the code say what, instead of how.


          Range

             1..10       from 1 to 10
             1..<10    from 1 to 9

             10..1     reverse range
           
             the range elements must implement ++, -- and <=>.

             for in range loop

             index -1 means last element.

          Groovy的Command還是要少用,加上括號吧

          List

               java.util.List

               list = new LinkedList()
               list[0] = 1

              an array from Java to Groovy => converted to a list

              toList()  method, convert a collection to a list

             The list’s getAt() and putAt() are overloaded with the parameters: integer, integers, range, 

             list[0..2] returns a sublist, not a new list, changing in the sublist, change the original list.

             list.inject(initial) { accumulator, index -> f(accumulator, index) }

          duck typing
              as long as something walks like a duck and talks like a duck, 
              we happily treat it as a duck.

          Map

              java.util.Map

             access map
                1. subscript operator map[key], getAt()
                2. dot operator .
                3. method get(), default value

          ConcurrentModificationException

              structurelly changing while iterating, such as list.each

          Copy Semantics and Modify Semantics

              works on a copy of the collection, collect, find, grep
              works in place, e.g. add()

          posted on 2007-12-13 01:26 gr8vyguy 閱讀(525) 評論(0)  編輯  收藏 所屬分類: Java

          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          公告

        1. 轉載請注明出處.
        2. msn: gr8vyguy at live.com
        3. 常用鏈接

          留言簿(9)

          隨筆分類(68)

          隨筆檔案(80)

          文章分類(1)

          My Open Source Projects

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 建昌县| 陇西县| 阿图什市| 莱芜市| 温州市| 图们市| 合作市| 永泰县| 赤峰市| 广宁县| 旺苍县| 花莲县| 鄂伦春自治旗| 玉门市| 泽州县| 杭锦旗| 收藏| 民丰县| 集贤县| 城口县| 普格县| 社旗县| 宁德市| 昆山市| 兴和县| 芒康县| 邓州市| 苗栗市| 大埔县| 马鞍山市| 景谷| 崇州市| 垣曲县| 田林县| 永济市| 南雄市| 会泽县| 博乐市| 洮南市| 启东市| 海盐县|