Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why illegal start of declaration in Scala?

Tags:

scala

For the following code:

package FileOperations
import java.net.URL

object FileOperations {
    def processWindowsPath(p: String): String {
        "file:///" + p.replaceAll("\\", "/")
    }
}

Compiler gives an error:

> scalac FileOperations.scala
FileOperations.scala:6: error: illegal start of declaration
        "file:///" + p.replaceAll("\\", "/")

Why? How to fix?

like image 618
Basilevs Avatar asked Oct 18 '10 04:10

Basilevs


2 Answers

You're missing an = from the processWindowPath method declaration.

package FileOperations
import java.net.URL

object FileOperations {
    def processWindowsPath(p: String): String = {
        "file:///" + p.replaceAll("\\", "/")
    }
}
like image 134
Jon McAuliffe Avatar answered Oct 10 '22 02:10

Jon McAuliffe


object FileOperations {
  def processWindowsPath(p: String): String  = {
    "file:///" + p.replaceAll("\\", "/")
  }
}

There is a missing =. Methods in Scala are defined this way:

def methodName(arg1: Type1, arg2: Type2): ReturnType = // Method body
like image 27
michael.kebe Avatar answered Oct 10 '22 02:10

michael.kebe