scala - add a tuple to listBuffer -


I want to add a three-integer tool in a ListBuffer. Intuitively, my first try is the code snippet 1, which is a syntax error, according to the compiler. Then, I tried Snippet 2 and 3, both would work, can someone explain to me why the code syntax is incorrect in Snippet 1

Snippet 1

  Import Scala.collection.mutable.ListBuffer val b: ListBuffer [(Int, Int, Int) ListBuffer () b + = (1, 1,1)  

snippet 2

  import scala.collection.mutable.ListBuffer val b: ListBuffer [(Int, Int, Int)] ListBuffer () B + = ((1,1,1))  

snippet 3

  import scala.collection.mutable.ListBuffer val b: ListBuffer [(Int, Int, Int)] = ListBuffer () val I = (1,1 , 1) b + = i  

  b + = (1,1,1)  

is interpreted as

  b. = = (1, 1, 1)  

which looks like a function call

Adding another connected leg Means it means

  b. = ((1,1,1))  

which is passing the expected tuple.

Declaring the argument separately

  val i = (1,1,1)  

is also not interpreted as a problem That's fine too.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -