I am having some strange compiler errors that I cannot seem to understand. Below is the relevant code:
class A {
var x = List[B]()
def func = {
val temp = x(0)
x = x tail
temp
}
}
I simply want to remove the first element from a list and return it. However, I am getting an error saying “type mismatch: found B: required Int”. I cannot figure out for the life of me why it wants an Int.
Thanks in advance for any help!
What is the type
B? Did you meanInt?To get the first element you can use
head. To get the rest of the list you can usetail. The dot operator in Scala is optional.