1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
def getSomething() {
"getSomething return value"
1000
}
println getSomething()
String getString() { return "I am a string" }
println getString()
def x = 1 def doubleQuoteWithDollar = "I am $x dolloar" def singleQuote = 'I am $x dolloar' println doubleQuoteWithDollar println singleQuote
def int y = 1 println y.getClass() println y.getClass().getCanonicalName()
def aList = [5, 'string', true] println aList
assert aList[1] == 'string' assert aList[5] == null aList[100] = 100 assert aList[100] == 100 println aList.size
def aMap = ['key1': 'value1', 'key2': true] println aMap['key1'] def key1 = "wowo" def aConfusedMap1 = [key1: "aConfusedMap1"] println aConfusedMap1.key1 def aConfusedMap2 = [(key1): "aConfusedMap2"] println aConfusedMap2.wowo println aConfusedMap2['wowo']
def aRange = 1..5 println aRange def aRangeWithoutEnd = 1..<5 println aRangeWithoutEnd.from println aRangeWithoutEnd.to
def aClosure = { String param1, int param2 -> println "this is code $param1,$param2" }
aClosure('hello', 1) aClosure.call('hello', 1)
def greeting = { "Hello, $it!" } assert greeting('Patrick') == 'Hello, Patrick!'
def noParamClosure = { -> true }
def iamList = [1, 2, 3, 4, 5] iamList.each { println it }
iamList.each({ println it })
def testClosure(Closure closure) { closure() }
testClosure { println "i am in closure" }
def aaMap = [k1: 'value1', k2: true] def results = aaMap.findAll { key, value -> println "scan : key=$key,value=$value" if (key == 'k1') return true return false } print results
thisX = 1 def printx() { println thisX }
printx()
def smallX = 1 def printSmallx() { println smallX; }
import groovy.transform.Field;
@Field fieldX = 1 def printFieldX() { println fieldX }
printFieldX()
def srcFile = new File('/Users/xiaoyue26/input') srcFile.eachLine { println it }
def targetFile = new File('/Users/xiaoyue26/output') targetFile.withOutputStream { os -> srcFile.withInputStream { ins -> os << ins } }
|