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

The Archive Base Latest Questions

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

How would you compare Scala’s object testability compare to testing statics in Java? Any

  • 0

How would you compare Scala’s object testability compare to testing statics in Java? Any pitfalls and traps?

Thank you.

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

    The same as statics in Java – references to objects are hard to swap for testing purposes, so you generally want to avoid them, except for side-effect-free, stateless utility methods, like Math.min, Math.max. Like in case of Java statics, objects holding state make testing particulary hard.

    Scala objects have one advantage over the Java static, though – you can make your object extend some supertype and refer to through that interface. Then you can inject that object to the constructor of your client class, so your client gets more testable:

    object MyRunnable extends Runnable {
      def run() { }
    }
    
    class Client(r: Runnable) {
      // ..
    }
    
    new Client(MyRunnable)
    new Client(mock[Runnable]) // you can substitute the object with a mock for tests
    

    With plain Java static, that is impossible. You can do similar thing with singletons in Java (to which Scala objects are similar).

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

Sidebar

Related Questions

i would like to change the way SBT for Scala presents informations. Any ideas
Are there any published micro-benchmarks that compare the Scala mutable and immutable collections with
Does anyone have any white papers or articles that would compare and contrast a
I would like to compare a screenshot of one application (could be a Web
I would like to compare the contents of a couple of collections in my
I would like to compare two dates in javascript. I have been doing some
I would like to compare two tables and then update if some logic is
I would like to compare 4 character string using wildcards. For example: std::string wildcards[]=
In my Nant script I would like to compare a property value to a
I have two arrays that I would like to compare and ultimately wind up

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.