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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:37:31+00:00 2026-06-03T04:37:31+00:00

In Scala, I have a case class: case class MonthSelectionInfo(monthSelection: MonthSelection.Value, customMonth:Int = 0,

  • 0

In Scala, I have a case class:

case class MonthSelectionInfo(monthSelection: MonthSelection.Value, customMonth:Int = 0, customYear:Int = 0) {

 def this(monthSelection: MonthSelection.Value) = {
   this(monthSelection, 0, 0)
 }
}


object MonthSelection extends Enumeration {
  type MonthSelection = Value

  val LastMonth, ThisMonth, NextMonth, CustomMonth = Value
}

When I have an instance of the case class, I have to use

myMonthSelectionInfo.monthSelection

and

myMonthSelectionInfo.eq(newMonthSelection)

to get & set the MonthSelection instance contained within.

Is there any nice Scala way to format the getter & setter to look more like regular Java POJOs? e.g.

myMonthSelectionInfo.setMonthSelection(newMonthSelection)
  • 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-03T04:37:32+00:00Added an answer on June 3, 2026 at 4:37 am

    There is @BeanProperty annotation to generate getters and setters for fields.

    case class MonthSelectionInfo(@reflect.BeanProperty var monthSelection: MonthSelection.Value)
    
    scala> val ms = MonthSelectionInfo(MonthSelection.LastMonth)
    ms: MonthSelectionInfo = MonthSelectionInfo(LastMonth)
    
    scala> ms.setMonthSelection(MonthSelection.ThisMonth)
    
    sscala> ms.getMonthSelection
    res4: MonthSelection.Value = ThisMonth
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this case class define: class Protocol(protocol:String) object Protocol { def apply(protocol:String) :Protocol
I have the following Scala class: case class Person(firstName: String, lastName: String, age: Int)
Is there a nicer way of doing this? scala> case class A(x : Int)
Scala programmer should have known that this sort of writing : class Person{ var
In Scala IDE I have the following code: package pkg.one object S { class
In Scala, I can make a caseclass, case class Foo(x:Int) , and then put
I have some code like this: case class FunctionCommand[A](function: Function1[Array[A], Unit]) class MyClass(commands: List[FunctionCommand[_]])
I have something like this in scala: abstract class Point[Type](n: String){ val name =
Does Scala have a version of Rubys' each_slice from the Array class?
Disclaimer: absolute novice in Scala :( I have the following defined: def tryAndReport(body: Unit)

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.