groovy变量

2020-03-15  本文已影响0人  龙剑灵
int x = 10

double y = 3.14

println x.class //class java.lang.Integer
println y.class //class java.lang.Double

k = 5
println k.class //class java.lang.Integer
k = 'adss'
println k.class //class java.lang.String

def a = 11
println a.class //class java.lang.Integer

b = 'FFF'
println b.class //class java.lang.String

c = 3.1415
println c.class //class java.math.BigDecimal

color = [red:"fff", green:"ggg"]
color.yellow = 'yyy'
println color['red'] //fff
println color.getClass() //class java.util.LinkedHashMap

println color.toMapString() //[red:fff, green:ggg, yellow:yyy]


def name = '吉米'
str = "hello, ${name}"
println str
println str.class  //class org.codehaus.groovy.runtime.GStringImpl

def sum =  "1 and 2 and ${1+2}"
def result = echo(sum)
println result //1 and 2 and 3
println result.class //class java.lang.String

String echo(String msg) {
    return msg
}
println result.equals('1 and 2 and 3') //true
上一篇下一篇

猜你喜欢

热点阅读