In below class is my main method not defined correctly ? When I try to run it from Eclipse I dont have the option to run it as a scala program. When I remove filesEnding(".txt") I can then run the program.
object FileMatcher {
private def filesHere = (new java.io.File(".")).listFiles()
private def filesMatching(matcher: String => Boolean) =
for(file <- filesHere; if matcher(file.getName))
yield file
def filesEnding(query: String) = filesMatching(_.endsWith(query))
def main(args:Array[String]) = {
filesEnding(".txt")
}
}
Main must return type
Unit. ButfilesEndingdoes not returnUnit, it returns files. The easiest fix is to remove the=so the return value from the method defaults toUnit.