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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:09:10+00:00 2026-06-01T10:09:10+00:00

Scala programmer should have known that this sort of writing : class Person{ var

  • 0

Scala programmer should have known that this sort of writing :

class Person{
   var id  = 0 
}
var p = new Person 
p.id 
p.id = 2    

equals to

class Person{
private var _id = 0 
def id = _id
def id_=(i: Int) = _id = i
}
val p = new Person 
p.id // be equal to invoke id method of class Person
p.id = 2   // be equal to p.id_=(2) 

in effect. But if you comment the getter method def id = _id , p.id = 2 will cause a compilation error, saying

error: value key is not a member of Person 

Could anyone explain why ?

  • 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-01T10:09:11+00:00Added an answer on June 1, 2026 at 10:09 am

    The compiler is so because the specification says so.

    See the Scala Reference, p. 86, §6.15 Assignments.

    Note that nothing prevents you from:

    • making the getter private
    • making the getter return another type
    • making the getter “uncallable”, e.g. like this: def id(implicit no: Nothing)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This semester in university I have a class called Data Structures, and the professor
I want to have classes that can mix only specified traits: class Peter extends
I'm new to Scala & sbt, and I'm trying to compile a project that
I'm new to Scala. I just installed sbt for windows MSI I have a
I'm a completely newbie Scala programmer, and I have no previous experience with Java;
I am new to Scala but an experienced programmer trying to shed old habits
scala> class A (s: String*) { val l: ListBuffer[String] = ListBuffer[String](s) } <console>:8: error:
scala> class A defined class A scala> trait B defined trait B Creating an
I have an issue that I feel many programmers can relate to... I have
While writing Scala RemoteActor code, I noticed some pitfalls: RemoteActor.classLoader = getClass().getClassLoader() has to

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.