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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:11:16+00:00 2026-05-23T13:11:16+00:00

I get the coding in that you basically provide an object SomeClass and a

  • 0

I get the coding in that you basically provide an “object SomeClass” and a “class SomeClass” and the companion class is the class declaration and the object is a singleton. Of which you cannot create an instance. So… my question is mostly the purpose of a singleton object in this particular instance.

Is this basically just a way to provide class methods in Scala? Like + based methods in Objective-C?

I’m reading the Programming in Scala book and Chapter 4 just talked about singleton objects, but it doesn’t get into a lot of detail on why this matters.

I realize I may be getting ahead of myself here and that it might be explained in greater detail later. If so, let me know. This book is reasonably good so far, but it has a lot of “in Java, you do this”, but I have so little Java experience that I sort of miss a bit of the points I fear. I don’t want this to be one of those situations.

I don’t recall reading anywhere on the Programming in Scala website that Java was a prerequisite for reading this book…

  • 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-23T13:11:17+00:00Added an answer on May 23, 2026 at 1:11 pm

    Yes, companion singletons provide an equivalent to Java’s (and C++’s, c#’s, etc.) static methods.

    (indeed, companion object methods are exposed via “static forwarders” for the sake of Java interop)

    However, singletons go a fair way beyond this.

    • A singleton can inherit methods from other classes/traits, which can’t be done with statics.
    • A singleton can be passed as a parameter (perhaps via an inherited interface)
    • A singleton can exist within the scope of a surrounding class or method, just as Java can have inner classes
    • It’s also worth noting that a singleton doesn’t have to be a companion, it’s perfectly valid to define a singleton without also defining a companion class.

    Which helps make Scala a far more object-oriented language that Java (static methods don’t belong to an object). Ironic, given that it’s largely discussed in terms of its functional credentials.

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

Sidebar

Related Questions

I have a simple object that get's geocoding data from the Google Maps API
I've seen that it's possible to get the latitude and longitude (geocoding, like in
I'm coding a small CMS to get a better understanding of how they work
I'm coding some c# against Active Directory and have tried endlessly to get this
I'd really like to get into some D3D coding, but I don't have the
We get the following error; The request was aborted: Could not create SSL/TLS secure
We get a large amount of data from our clients in pdf files in
I get an Access is Denied error message when I use the strong name
I get a URL from a user. I need to know: a) is the
There are some good geocoding plugins (e.g. geokit) but can you recommend a googlemaps

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.