测试方法:

/** * Created by intbird on 17/5/9. */class GroovyClass {    static void main(args) {        def basic = new GroovyBasic(basicInfo: "init groovy basic info")        //自带属性        basic.basicInfo = "groovy basic info"        basic.setBasicInfo("set groovy basic")        //空指针检查        basic.nullPointCheck("hello")        basic.nullPointCheck(null)        //基础方法//        basic.defCondition()//        basic.repeatVar()//        basic.repeatVar(3)//        basic.collectionType()//        basic.mapType()//        basic.delegateType()        basic.delegateMethod()    }}

基础语法:

/** * Created by intbird on 17/5/9. */class GroovyBasic {    def basicInfo;    void nullPointCheck(value){        println(value?.class?.toString())    }    void defCondition() {        def x = 1        println(x.class)        def array = 1..5        println(array.class)        def array2 = [1, 2, 3, 4, 5]        println(array2.class)        def map = ["1": "string", "2": "integer"]        println(map.class)        println('\n')    }    void repeatVar(repeatVarMax = 5) {        for (x in 1.."repeat groovy val:$x")        }        println('\n')    }    void collectionType() {        def collection = [1, 2, 3, 4]        collection.add(5)        println(collection.toArray())        Collection coll = new ArrayList()        coll.addAll(collection)        coll.add(6)        coll << 7        println(coll.toArray())        coll = coll - [1, 2, 3]        println(coll.toArray())        coll = coll + [8, 9, 10]        println(coll.toArray())        println('\n')    }    void mapType() {        def map = [1: "value1", "key2": 2]        println(map.toString())        map.put(3, "value3")        println(map.toString())        println(map[1])        println(map.key2)        println(map.get(3))        println('\n')    }    void delegateType() {        def array = [1, 2, 3, 4]        array.each {            it = it + 10        }        println(array.toString())        def map = [1: "呵呵", 2: "滚开"]        map.each {            key, value ->                println(key + " value:$value")        }        println(map.toString())    }    void delegateMethod() {        def values = delegateCursor(1)        println("delegateValue:$values")    }    def delegateCursor = {        value ->            value = value + 10            return value    }}

更多相关文章

  1. Android Post方法请求URL 迭代器
  2. Android DEX方法超过64K和gradle编译OOM解决方案
  3. Android下按扭的使用方法
  4. API 23及之后版本关于用android studio 中LocationManager的方法
  5. Android:获取屏幕分辨率方法汇总
  6. android获取屏幕长宽的方法
  7. android 进程自杀再重启的方法
  8. Android监听HOME键的最简单的方法

随机推荐

  1. Android ClassLoader
  2. android----制作splash镜像
  3. Android] ImageView.ScaleType设置图解
  4. [原创]通过代码及流程图说明Google在Andr
  5. svn E155037:Previous operation has not
  6. android实现一键锁屏
  7. Android视频文件格式解析相关分析
  8. 原生Android缩略图填满SD卡的问题
  9. 第三十六天 一乐在其中—Android的按钮单
  10. 适用于 Android 8.0 及以下全部版本的拍