方法的默认值

时间:2014-12-19 06:57:21

标签: dictionary methods groovy default-value

我试图将默认值指定为Map。这是它的完成方式吗?

static def AddOrder( String key, Map order = [
                                                id: '',
                                                campaign_id: '',
                                                email_id: '',
                                                email: '',
                                                total: 0.0d,
                                                order_date: '',
                                                shipping: 0.0d,
                                                tax: 0.0d,
                                                store_id: '',
                                                store_name: '',
                                                items:  [
                                                            line_num: 0,
                                                            product_id: 0,
                                                            sku: '',
                                                            product_name: '',
                                                            category_id: 0,
                                                            qty: 0.0d,
                                                            cost: 0.0d
                                                        ]
                                            ] ){
    contactMC( key, action, order)
}

1 个答案:

答案 0 :(得分:1)

为什么不测试它?一个非常短的程序将向您展示确实,默认地图参数的工作方式:

def testMethod(Map map = [ foo: 'bar' ]) {
    return map.foo
}

println testMethod() //outputs bar
println testMethod([foo:'baz']) //outputs baz
相关问题