Android:Groovy基础语法
来源:互联网 发布:羽毛球步伐训练软件 编辑:程序博客网 时间:2024/06/06 08:40
测试方法:
/** * 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..<repeatVarMax) { println("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 }}
0 0
- Android:Groovy基础语法
- Groovy基础语法
- Groovy的基础语法
- Groovy的基础语法
- groovy语法基础
- Groovy的基础语法
- groovy语法基础
- Groovy语言语法基础
- Groovy基础语法总结
- Groovy语法基础
- gradle学习(12)-groovy一些基础语法
- Android中涉及到的Groovy语法
- groovy语法
- Groovy 和 Gradle (Android Studio)基础
- Groovy基础
- Groovy基础
- Groovy基础
- groovy基础
- JS学习(七)----标准对象日期
- H3C S5120端口镜像配置
- 6.0运行时权限与targetSdkVersion选择
- (13.1.3.7)PMBOK之三:十大知识领域之沟通管理
- 自定义注解
- Android:Groovy基础语法
- linux切换到root
- 怎么用spring mvc处理form表单的ajax验证
- KeyStone服务安装配置
- 读书笔记(一)
- 扫雷外挂
- 深入解读缓存(二)——一致性Hash算法
- 微信JS-SDK PHP Demo JS接口安全域名 自定义分享接口 jsapi_ticket
- oracle数据库怎么创建新用户