Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7008447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:44:09+00:00 2026-05-27T21:44:09+00:00

I am learning Scala with Scala-IDE in Eclipse. While following the Chapter 9: Control

  • 0

I am learning Scala with Scala-IDE in Eclipse. While following the Chapter 9: Control Abstraction, part 1: Reducing Code Duplication in the Programming in Scala book, I have written the code from the book (fully represented below), it worked fine! When I started removing the unnecessary blank lines, a strange thing happened. Here is the entire code before the removal of the blank lines in the filterFiles() method:

object Code_c09s01_ControlAbstraction extends App{

  object FilesFilter {

    private def filterFiles(path: String, pattern: String, matcher: (String, String) => Boolean) = {

      val files = (new java.io.File(path)) listFiles

      for(file <- files if matcher(file.getName, pattern)) yield file
    } 

    def filterExtension(path: String, pattern: String) = filterFiles(path, pattern, _.endsWith(_))
    def filterName(path: String, pattern: String) = filterFiles(path, pattern, _.contains(_))
    def filterRegex(path: String, pattern: String) = filterFiles(path, pattern, _.matches(_))
  }

  def printArray[A](message: String, arr: Array[A]) {
    println (message)
    println (arr mkString("\n"))
  }

  def test() {
    val path = "C:\\";

    printArray("--- filtering by ext: ---", FilesFilter.filterExtension(path, ".txt"))
    printArray("--- filtering by containment: ---", FilesFilter.filterName(path, "1"))
    printArray("--- filtering by regex: ---", FilesFilter.filterRegex(path, "."))
  }

  test

}

which works just fine! However, after removing the blank lines from the filterFiles() method, the method now looks like this:

private def filterFiles(path: String, pattern: String, matcher: (String, String) => Boolean) = {
  val files = (new java.io.File(path)) listFiles
  for(file <- files if matcher(file.getName, pattern)) yield file
} 

And the IDE gives me errors on both lines of the body. The error of the first line says:

ambiguous reference to overloaded definition, both method listFiles in class File of type (x$1: java.io.FileFilter)Array[java.io.File] and method listFiles in class File of type 
 (x$1: java.io.FilenameFilter)Array[java.io.File] match argument types (Null)

the error on the second line says:

illegal start of simple expression

and all the three calls to the printArray() in the test() method now also tell this:

type mismatch; found : Unit required: Array[?]

What does it all mean? Scala is not supposed to behave like Python when code alignment can ruin the code flow… so how come that removing the blank line between the first and the second line of the body of the filterFiles() method puts up such a serious error? Is it a bug somewhere or does it follow directly from the rules of Scala? Note: if I add ; between the line, it sorts everything out. Is it just semicolon inference bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:44:10+00:00Added an answer on May 27, 2026 at 9:44 pm

    When object’s method can none or single argument you can call it like

    val files = object method arg
    

    or, in your snippet

    val files = object method
      arg
    

    In your code compiler wants to call listfiles with an for expression as an agument which returns Array[File]. And complains that listFiles hasn’t implementation with this type of argument. Empty line prevents treating for expression as a parameter for listFiles function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Which IDE for Scala 2.8? I'm learning Scala by reading 'Programming in
I'm learning Scala and trying to use javax.cache in Scala code and can't find
I just ran into a difficulty while learning Scala. I have an inheritance hierarchy
I'm currently learning scala. Why this code doesn't work: class GenClass[T](var d : T)
L.S. I'm just learning Scala using Programming in Scala by Odersky et al. In
Chapter 2 of the new Manning book, Scala in Depth by Josh Sueresh is
Learning Scala currently and needed to invert a Map to do some inverted value->key
I'm learning Scala, so this is probably pretty noob-irific. I want to have a
I'm learning Scala and there is a thing that I can't find out about
I have been learning Scala for the past couple of months and now I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.