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

  • Home
  • SEARCH
  • 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 8055453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:23:23+00:00 2026-06-05T08:23:23+00:00

Writing out a Scala class and problem here is that the compiler thinks that

  • 0

Writing out a Scala class and problem here is that the compiler thinks that the code is a unit not returning the proper value. It’s a method used to set a property in the class:

def setObject(`object`:StripeObject):StripeObject = {
    this.`object` = `object`
  }

The error is: type mismatch; found : Unit required: com.stripe.StripeObject

The full class is:

case class EventData(var previousAttributes: HashMap[String,Object], var `object`:StripeObject) extends StripeObject {

  def getPreviousAttributes = {
    previousAttributes
  }

  def setPreviousAttributes(previousAttributes: HashMap[String, Object]) = {
    this.previousAttributes = previousAttributes
  }

  def getObject = {
    `object`
  }

  def setObject(`object`:StripeObject):StripeObject = {
    this.`object` = `object`
  }
}

How do I make sure it doesn’t return a Unit?

  • 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-05T08:23:27+00:00Added an answer on June 5, 2026 at 8:23 am

    In Java setters are usually defined with void return type:

    public void setObj(StripeObject name);
    

    The Scala equivalent is Unit, which is also the value of an assignment expression. So in Scala you’d write a setter as one of the following (which are all equivalent, with the first being the most idiomatic):

    def setObj(obj: StripeObject) {
      this.obj = obj
    }
    
    def setObj(obj: StripeObject): Unit = {
      this.obj = obj
    }
    
    def setObj(obj: StripeObject) = this.obj = obj
    

    This is just a convention for setters, though, and you could easily return the value if you wanted:

    def setObj(obj: StripeObject): StripeObject = {
      this.obj = obj
      obj
    }
    

    This would be a bit unusual, but wouldn’t be likely to cause problems, even for callers who were expecting Unit.

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

Sidebar

Related Questions

Writing Scala code, I regularly encounter cases where I have processor functions that operate
I've heard that writing out the entire ASP.NET page in one go helps performance.
I have a list of string that I am writing out to a CSV
I'm writing a bunch of data out from a java application that gets consumed
I'm writing a java program that goes out and searches twitter, finds certain instagram
I find that writing web apps and WinForm apps generally come out a lot
What is the proper of writing the standard read-while loop in Scala? By proper
I'm in scala writing a serializer that saves an object (or Model) to the
I am writing a Scala class to inherit from a Java class, and I
I am writing a program that does some unit conversions from a Brix scale

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.