tags:

views:

74

answers:

2

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?

+8  A: 

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("\\", "/")
    }
}
Jon McAuliffe
All scala tutorial listings are missing of that symbol http://www.scala-lang.org/docu/files/ScalaTutorial.pdf
Basilevs
Yup, there's a lot of code there that doesn't return a value. If the method returns a value, you need the = sign. Page 8 has the first example in the linked document.
Jon McAuliffe
Do these function return value? If they don't they're not supposed to use `=`.
Elazar Leibovich
Yes, only functions that doesn't return a value are without = sign in tutorial.
adelarsq
+5  A: 
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
michael.kebe