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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:23:42+00:00 2026-05-31T06:23:42+00:00

Just like the question. Does scala promote it same way as Java? Or has

  • 0

Just like the question. Does scala promote it same way as Java? Or has it been evolved to be more idiomatic to Scala? Or has it been made irrelevant?

POJOs and JavaBeans meaning:

  1. Constructor that takes no parameters
  2. attributes are private, getters and setters are public
  3. getters and setters defines properties, hiding attributes

Also, does Scala have opinions (sorry, I dislike using this term) on using the old public, private, protected attribute designs that is relevant to this question?

  • 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-31T06:23:43+00:00Added an answer on May 31, 2026 at 6:23 am

    Scala also has POJO-like idioms but they are different than JavaBeans and Scala puts emphasis on different aspects.

    1. Scala has different naming conventions:

      def foo: Foo        //Foo getFoo() in Java
      def foo_=(foo: Foo)  //void setFoo(Foo foo) in Java
      

      This way you can always write obj.foo and obj.foo = bar even if you decide to switch from getters/setters to direct field access and vice-versa. This is called uniform access principle.

    2. Due to Java interoperability, @BeanProperty annotation was introduced:

      @BeanProperty var foo: Foo = _
      

      the code above not only creates Scala-like getters/setters, but Java-like as well, so all Java frameworks work seamlessly.

    3. Scala forces you to decide between variables (var) and values (val), so you find yourself much more often using immutable objects

    4. I really prefer immutable objects and initialization in constructor, which has been made very easy in Scala:

      class Foo(val age: Int, val name: String)
      

      or even (val by default in case classes):

      case class Foo(age: Int, name: String)
      

      This piece of code is brilliant in its simplicity. However, if you need to cooperate with Java frameworks, you still need no-argu constructor and setters:

      public class Foo(var age: Int, var name: String) {
      
          def this() {
              this(0, "")
          }
      
      }
      

      Note val being replaced by var.

    5. Access modifiers in Scala have slightly better defaults compared to Java:

      class Foo(var a: Int, x: Int) {
      
          var b: Int = _
      
          private var c: Int = _
      
          private[this] var d: Int = _
      
          def twisted = a + b + c + d + x
      
      }
      

      Variables a and b will become private fields with public getters/setters (fields are private by default, methods are public). c and d are private variables as well. But the extra private[this] makes d be accessible directly internally in the class rather than by private getter/setter.

      Because x is used somewhere beside the constructor, Scala automatically creates private field for it as well. However no getters/setters are generated, it is accessed directly in twisted method (same as d).

    UPDATE: In comments you are asking about renaming getters/setters. Here is even more complex example. Getters/setters are computing the value based on two fields at the same time:

    class Foo {
    
        private[this] var first: Char = _
        private[this] var rest: String = _
    
        def fake = first + rest
    
        def fake_=(s: String) {
            first = s.head
            rest = s.tail
        }
    
    }
    

    Looks complicated inside, but from the outside it looks like good old property:

    val foo = new Foo()
    foo.fake = "ABC"
    println(foo.fake)
    

    Just like if it was:

    class Foo(var fake: String)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just like the question asks. Does 5.4 address this?
Just like Carl's question over here I would like to ask you (because I
Just like stackoverflow, there is a many-to-many relationship between Question and Tag. After running
I read on another Stack Overflow question that Python was just like Ruby, as
This may sound like a stupid question but I'm a beginner not just to
Just a quick question. Say a call a method like so mysql_pconnect(server,tator_w,password) or die(Unable
I have a question that I just don't feel like I've found a satisfactory
Just like in JavaScript : opener.document.getElementByName jQuery: ?? Is there any way to get
This is barely even a question, I'd just like someone to confirm this for
The question says it all, really. I know a (Scala) Monad looks like this:

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.