Surender Raja Surender Raja - 8 months ago 34
Scala Question

Scala compile time error while calling a method by passing List[Record]

I am doing some basic handson in scala.. i am getting compile-time error at the place of defining a method called processList.

The compile time error is

Multiple markers at this line:
- only classes can have declared but undefined

My code is as follows,

package pack1


case class Record(id:Int, name:String, city:String)

object ReadingFile {

def main(args: Array[String]): Unit = {
val fileLoc:String = "/home/edureka/surender/inputfiles/records.txt"

val fileData:List[String] = Source.fromFile(fileLoc).getLines().toList

val fileList { eachLine => {
val Array(a:String,b:String,c:String) = eachLine.split(",")
} }




def processList(myList:List[Record])




I dont know how to fix this, Can somebody help me on this?


Because of the new line after def processList(myList:List[Record]) Scala compiler thinks that the method implementation is not given and below block {} does not belong to the method. So compiler thinks its a abstract method.

Declare processList like this

 def processList(myList:List[Record]) {



 def processList(myList:List[Record]): Unit = {


Instead of this

def processList(myList:List[Record])
                                     //remove this line to fix the error