美文网首页
groovy变量

groovy变量

作者: 龙剑灵 | 来源:发表于2020-03-15 22: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
    

    相关文章

      网友评论

          本文标题:groovy变量

          本文链接:https://www.haomeiwen.com/subject/xwxbdhtx.html