Reputation: 44061
I would expect identical output to be produced but instead I get the following
string1,string2
WrappedArray(string1, string2)
.
def appendcsv(fileName: String, args: Any*) {
val fw = new FileWriter(fileName, true)
val line = args.mkString(",")
fw.write(line + "\r\n")
fw.close()
}
def printcsv(fileName: String, args: Any*) {
appendcsv(fileName, args)
}
appendcsv("test.csv", "string1", "string2")
printcsv("test.csv", "string1", "string2")
Upvotes: 3
Views: 129
Reputation: 8821
Because when you do appendcsv(fileName, args)
, you are passing a WrapedArray instead of multiple arguments as you will expected. So in facts appendcsv
only received only one argument of WrappedArray, not two strings.
You could use appendcsv(fileName, args: _*)
to expend array to multiple arguments, and it will be what you would expected.
Upvotes: 14