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

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 太和县| 满城县| 建阳市| 漳州市| 沙河市| 丹棱县| 阜新市| 潢川县| 平舆县| 信宜市| 望城县| 盐池县| 荣昌县| 奉贤区| 漾濞| 广水市| 乐平市| 祁连县| 晋江市| 清镇市| 电白县| 阿坝| 柘荣县| 林周县| 酉阳| 女性| 南溪县| 敦煌市| 南宫市| 北安市| 新建县| 林州市| 百色市| 兴仁县| 梁河县| 浏阳市| 乐清市| 时尚| 册亨县| 德兴市| 论坛|