Reputation: 623
I need some guidance here, please.
What I have:
import scala.collection.mutable.ArrayBuffer
var buffer = ArrayBuffer.empty[(Double, Double)]
and I want to fill the buffer with pairs. I'm trying this but it doesn't work:
for(someCycle){
buffer += (someDouble, someOtherDouble)
}
the error:
error: type mismatch;
found : Double
required: (Double, Double)
buffer += (someDouble, otherDouble)
I understand the error but I can't figure out the right syntax.
Upvotes: 1
Views: 308
Reputation: 149518
Since +=
is a function, the compiler is inferring it as:
buffer.+=(someDouble, someOtherDouble)
Making it think you're trying to pass two arguments to +=
instead of one (the error message is a bit misleading).
You need an additional parenthesis:
buffer += ((someDouble, someOtherDouble))
Or alternatively:
buffer += (someDouble -> someOtherDouble)
Upvotes: 4