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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:33:32+00:00 2026-06-17T10:33:32+00:00

I have made heavy use of case classes in my code, replying on the

  • 0

I have made heavy use of case classes in my code, replying on the underlying equality definitions of case class to behave correctly. Then now I found that I need to add another field member to a case class.

  1. So if I add a var field member in case class, will it mess up the equality attributes for the case class?
  2. If 1 is yes, then what if I just change the var field value once, after that, no any reassignment will happen, before the case class goes into any collections or do equality comparison, will that still mess up the equality behaviors?
  • 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-17T10:33:33+00:00Added an answer on June 17, 2026 at 10:33 am

    Case class equality is based solely on its primary constructor attributes, whether they’re var or val (yes, you can make them var by giving an explicit var to override the implied val that case class constructor args possess.) Adding properties in the body of a case class does not influence the compiler-generated equals(other: Any) method.

    Witness:

    package rrs.scribble
    
    object  CCVarEq
    {
      case class CC1(i: Int, j: Float, var k: Double)
    
      case class CC2(i: Int, j: Float, var k: Double) {
        var l = math.Pi
      }
    
      def show {
        val cc11 = CC1(1, 2.0f, 3.0)
        val cc12 = CC1(1, 2.0f, 3.0)
    
        val cc21 = CC2(1, 2.0f, 3.0); cc21.l = math.E
        val cc22 = CC2(1, 2.0f, 3.0)
    
        printf("cc11 == cc12: %s%n", cc11 == cc12); cc12.k = math.Pi * math.E
        printf("cc11 == cc12: %s%n", cc11 == cc12)
    
        printf("cc21 == cc22: %s%n", cc21 == cc22)
      }
    }
    

    In the REPL:

    scala> import rrs.scribble.CCVarEq._
    import rrs.scribble.CCVarEq._
    
    scala> show
    cc11 == cc12: true
    cc11 == cc12: false
    cc21 == cc22: true
    

    And all jamie’s points about concurrency are valid, too.

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

Sidebar

Related Questions

Whilst programming Java GUis I made heavy use of the Action class. The instantiated
I have made a code that read data from flash Nand (without filesystem). fd
I have made my own exception class which derives from runtime_error and is getting
I have an app on the market which supports widgets. I've made some heavy
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I have an ETL process that involves a stored procedure that makes heavy use
I have made this code that makes some visual tiles that fades in and
I've been developing an app specifically for modern browsers and have made very heavy
i have a rails app which makes heavy use of activeresource and httparty to
I have made a jQuery toggle for a menu that I had in mind.

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.