Scala compiler error : only classes can have declared but undefined members

scala

Solution

Firstly `userList` is a `val` which means you need to initialize it. Secondly `userList` is of type `List[String]`. You cannot add `User` to it. This is how it should be:

val userList = List.empty[User]
userList :+ new User("1" , 1); 

Problem

Below class throws a compiler error at this line `val userList : List[User]` : ``` Multiple markers at this line - only classes can have declared but undefined members - only classes can have declared but undefined members ``` Here is the entire code : ``` class SimilarityData { case class User(id: String, jCoeff : Int) def getUsers() = { val userList : List[User] userList :+ new User("1" , 1); } } ``` What is causing this error ?

Original source