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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:11:05+00:00 2026-06-15T11:11:05+00:00

Assuming this code: def main(args: Array[String]) { val func = (x: String, y :String)

  • 0

Assuming this code:

  def main(args: Array[String]) {
    val func = (x: String, y :String) => x + ", " + y
    println(myFunc(func))
  }

  def myFunc(f: (String, String) => String) = {
    f("Hey","how are you?")
  }

The second line of this code is replaced by compiler to:

val func = new Function2[String, String, String] {
             def apply(x: String, y: String): String = x + ", " + y
           } 

I can deduce that func type in this case corresponds also to (String, String) => String) type, as the myFunc signature shows; meaning that Function2[String, String, String] is the same type as (String, String) => String.

Why different notations? Why Scala compiler hasn’t rather transformed the function literal to some kind of conceptual: new ((String, String) => String) without boring with Function2[String, String, String] type? Or vice versa.

One explanation would be that a class name cannot be multipart as: (T1, T2) => R.
But why not after all?

  • 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-15T11:11:06+00:00Added an answer on June 15, 2026 at 11:11 am

    Why Scala compiler hasn’t rather transformed the function literal to some kind of conceptual: new (String, String) => String

    Remember that Scala compiles down to JVM bytecode. There is no such thing as “conceptualnew (String, String) => String” in JVM. There are only objects and methods (at least until Java 8). In Java language you have to use boring Callable<T>, Runnable or various Function abstractions in Guava and Apache Commons. There is no way around it. From that perspective Scala basically hides Java boilerplate by adding syntactic sugar over anonymous FunctionX[...] classes.

    That’s also one of the reasons why Scala compiler has to do so much fiddling when you use a method where function was expected (so called eta expansion).

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

Sidebar

Related Questions

This program, after executing main(), does not exit. object Main { def main(args: Array[String])
Assuming sr is an IEnumerable<string> , I want to use code like this to
Assuming MyClass uses the default destructor (or no destructor), and this code: MyClass *buffer
Assuming I have a decorator and a wrapped function like this: def squared(method): def
I'm looking at this code in a Ruby library. Am I correct in assuming
Just created an acc on SO to ask this :) Assuming this simplified example:
I've recently taken over a project from another consulting firm. I'm assuming this can
I am missing this DLL reference in c:\program files\SQL Server\90\Tools\Binn. I'm assuming that this
Are there any way to access or set iphone's alarm? Im assuming if this
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a

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.