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 閱讀(520) 評論(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

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 温宿县| 德昌县| 类乌齐县| 溧阳市| 桓仁| 乐业县| 岢岚县| 新津县| 陇西县| 家居| 犍为县| 紫金县| 呼图壁县| 察哈| 五家渠市| 达日县| 犍为县| 安阳县| 江西省| 株洲市| 舒城县| 泽州县| 桂林市| 饶河县| 左贡县| 临江市| 商南县| 闽侯县| 布拖县| 高邑县| 恩平市| 和静县| 孙吴县| 宿迁市| 连平县| 松潘县| 靖边县| 芮城县| 泗阳县| 万全县| 沈阳市|