源自:5-4 方法对象
这个list2的值怎么也改变了?
void main() {
var list2 = ["h","e","l","l","o"];
print(listTimes(list2, times)); //打印 [hhh, eee, lll, lll, ooo]
print(list2); //打印 [hhh, eee, lll, lll, ooo]
//print(list); //报错不存在
}
List listTimes (List list, String f(str)) {
for (var index = 0; index < list.length; ++index) {
list[index] = f(list[index]);
}
return list;
}
String times(str) {
return str*3;
}
把list2传到listTimes里去,怎么list2也变成[hhh, eee, lll, lll, ooo]了,那要用到["h","e","l","l","o"]的时候怎么办。怎么改进
提问者:qq_什么清华北大不如胆子够大_0
2019-07-13 11:58