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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:28:20+00:00 2026-05-15T14:28:20+00:00

Does anyone know if something like this is possible in Scala: case class Thing(property:String)

  • 0

Does anyone know if something like this is possible in Scala:

case class Thing(property:String)

def f(thing:Thing, prop:String = thing.property) = println(prop)

The above code doesn’t compile; giving the error error: not found: value thing at thing.property

The following shows the expected behaviour:

f(Thing("abc"), "123") // prints "123"
f(Thing("abc"))        // prints "abc"

I realise I could make the prop argument an Option[String] and do the check in the function definition, but I was wondering if there was a way around it with the new named/default argument support in 2.8.0.

  • 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-15T14:28:20+00:00Added an answer on May 15, 2026 at 2:28 pm

    Yes, it’s possible in Scala 2.8. Here’s a quote from the “Named and Default Arguments in Scala 2.8” design document:

    Since the scope of a parameter extends
    over all subsequent parameter lists
    (and the method body), default
    expressions can depend on parameters
    of preceding parameter lists (but not
    on other parameters in the same
    parameter list). Note that when using
    a default value which depends on
    earlier parameters, the actual
    arguments are used, not the default
    arguments.

    def f(a: Int = 0)(b: Int = a + 1) = b // OK
    

    And another example:

    def f[T](a: Int = 1)(b: T = a + 1)(c: T = b)
    // generates:
    // def f$default$1[T]: Int = 1
    // def f$default$2[T](a: Int): Int = a + 1
    // def f$default$3[T](a: Int)(b: T): T = b
    

    According to this, your code may look as follows:

    scala> case class Thing(property:String)
    defined class Thing
    
    scala> def f(thing:Thing)(prop:String = thing.property) = println(prop)
    f: (thing: Thing)(prop: String)Unit
    
    scala> f(Thing("abc"))("123")
    123
    
    scala> f(Thing("abc"))()
    abc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if something like this is possible? Do a quick search, using
Possible Duplicate: C, Macro defining Macro Does anyone know how to pull off something
Does anyone know how to reset the instance variables via a class method. Something
Does anyone know whether it is possible to create a UDDT that is something
Does anyone know anyway to use something similar to polygon.getKml() except for the current
Does anyone know of a gamification gem? I'm looking for something that can provide
Does anyone know of a linux-compatible command line html formatter? You know, something where
Does anyone here know of a Javascript application (something similar to Lightbox, only not
I am wondering does anyone know if it is possible to render html in
Does anyone know if it is possible to use jQuery or Php to get

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.