基于this问题,我编写了以下代码,这会引发编译时错误:
以下是代码:
43. Currency currency = new Currency()
44. (currency.rate_one, currency.time_one) = getDateAndRate()
我的方法有两个返回值:
def getDateAndRate(){
Date date = new Date()
double rate = getRate();
return [rate, date]
}
引发错误
expecting '}', found ',' @ line 44, column 26.
(currency.rate_one, currency.time_one) = getDateAndRate()
^
答案 0 :(得分:2)
试试这个
def (rate, time) = getDateAndRate()
currency.rate_one = rate
currency.time_one = time
答案 1 :(得分:0)
我自己最近才学会了一个技巧,那就是结合多项任务和:
with (currency) {
(rate_one, time_one) = getDateAndTime()
}