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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:36:43+00:00 2026-06-08T14:36:43+00:00

Possible Duplicate: How does Scala's apply() method magic work? I am an absolute beginner

  • 0

Possible Duplicate:
How does Scala's apply() method magic work?

I am an absolute beginner in Scala and after reading in one of the Scala books that apply function is like “overloaded () operator” I began to wonder how tha is defined. Namely an operator () would take the argument between the brackets themselves, rather than in the conventional infix a () b notation. Is definition of such operator possible in Scala and if so, what is the definition syntax? Thanks.

  • 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-06-08T14:36:45+00:00Added an answer on June 8, 2026 at 2:36 pm

    As you already stated in your question, you simply define it by defining a method (not a function) called apply.

    foo(bar, baz)
    

    gets translated to

    foo.apply(bar, baz)
    

    So, as long as foo has an apply method of correct arity and type, this will work.

    Some examples of implementations of the apply method are the Array companion object, which allows you to construct an array by calling Array(1, 2, 3) (which is actually just Array.apply(1, 2, 3)) and the Array class, which allows you to access an array element by calling anArray(i) (which is actually just anArray.apply(i)).

    This is similar to e.g. Python, where function calls get translated into calls to the __call__ operator or Ruby, where an expression of the form foo.(bar, baz) gets translated to foo.call(bar, baz).

    A similar method is update:

    foo(bar) = baz
    

    gets translated to

    foo.update(bar, baz)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How does this bash fork bomb work? Today one of my friend
Possible Duplicate: What does :_* (colon underscore star) do in Scala? I’m using the
Possible Duplicate: How does this CSS triangle shape work? Please help me i need
Possible Duplicate: Does Java guarantee that Object.getClass() == Object.getClass()? If I have a class
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: What does the leading semicolon in JavaScript libraries do? I am reading
Possible Duplicate: How can I chain implicits in Scala? Can Scala apply multiple implicit
Possible Duplicate: Does java evaluate remaining conditions after boolean result is known Why do
Possible Duplicate: Does Dispose method still get called when Exception is thrown inside of
Possible Duplicate: Does a finally block always run? I learned that the finally clause

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.