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 6768467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:04:43+00:00 2026-05-26T15:04:43+00:00

I tried to make some sort of convenient class (below) to hold folder and

  • 0

I tried to make some sort of convenient class (below) to hold folder and get file by using filename (string). This work as expect but one thing I don’t understand is map part Map(folder.listFiles map {file => file.getName -> file}:_*).

I place :_* there to prevent some kind of type incompatible but I don’t know what does it really do. Also, what is _* and could I replace is with anything more specific ?

thanks

class FolderAsMap (val folderName:String){
  val folder = new File(folderName)
  private val filesAsMap: Map[String, File] = Map(folder.listFiles map 
                                          {file => file.getName -> file}:_*)

  def get(fileName:String): Option[File] = {
    filesAsMap.get(fileName)
  }
}
  • 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-26T15:04:44+00:00Added an answer on May 26, 2026 at 3:04 pm

    : _* is correct. Alternatively, you can use toMap:

    folder.listFiles map {file => file.getName -> file}.toMap
    

    Map(...) is method apply in object Map: def apply [A, B] (elems: (A, B)*): Map[A, B]. It has a repeated parameter. It is expected to be called with multiple parameters. The : _* is used to signal you are passing all the parameters as just one Seq argument.

    It avoids ambiguities. In java, (where equivalent varargs are arrays instead of Seqs) there is a possible ambiguity, if a method f(Object... args) and you call it with f(someArray), it could mean that args has just one item, with is someArray (so f receives an array of just one element, which its someArray), or args is someArray and f receives someArray directly). Java choose the second version. In scala, with a richer type system and Seq rather than Array the ambiguity may arise much more often, and the rule is that you always have to write : _* when passing all arguments as one, even when no ambiguity is possible, as in here, rather than a complex rule to tell when there is an actual ambiguity.

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

Sidebar

Related Questions

I tried to make an asynchronous UDP client using boost::asio I get some code
I've tried to extend the RequiredAttribute to make some localizations. I wrote this: public
I tried to make a new bare git repository but I get this error:
I am trying to make some sort of SQL Query where I only get
I tried to make a dynamic SQL which gets all tasks for some users
How to make a sticky footer i have tried on google found some results
I would like to make my own ThreadPool type class in Java (I tried
I have a plain text file looking like this: some text containing line breaks
Tried to make a little old school ajax (iframe-javascript) script. A bit of mootools
I tried to make an alert popup with A with: var a = \u0041;

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.