list - infix notation sometimes doesn't work in scala, why is that? -


alright, making tests familiar scala, , wanted see if make lists java style rather fancy way you'd in scala...

i know can this: val lst = list.range(0, 100, 1) wanted see java style in scala

alright here's did:

var lst = list[int]()  for(i <- 0 until 100) {     lst = lst :: // here's complains } 

for reason scala, or @ least scala ide eclipse doesn't append using infix notation, a-la lst :: i wants me this: lst.::(i) otherwise says :: isn't defined or something, it's not first time it's happened either...

so can here explain why that, or case of bad implementation in eclipse , have live with

in scala, list of immutable length. can work lifo (last in, first out) structure, cannot behave java arraylist.

you doing this:

val lst = list[int]() 

which gives lst size of 0. means can't it.

for mutable collection, use listbuffer.

also, :: operator right associative, means called on object found on right side of operator.

val lst = listbuffer[int]()  (i <- 0 until 100) {     lst += // add tail. } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -