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

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 富宁县| 报价| 山丹县| 达孜县| 桂平市| 秦安县| 温泉县| 烟台市| 鹤岗市| 西畴县| 民和| 汤原县| 文登市| 玉树县| 辽中县| 洞头县| 新干县| 开原市| 沿河| 南皮县| 淳化县| 成都市| 临武县| 永丰县| 阿克苏市| 镇巴县| 宁化县| 阿拉尔市| 沾益县| 龙井市| 大名县| 泌阳县| 麻江县| 阿合奇县| 西丰县| 乡城县| 海城市| 浙江省| 扎赉特旗| 太和县| 天津市|