The Artima Developer Community
Sponsored Link

Programming in Scala Forum
chapter 4, companion objects

1 reply on 1 page. Most recent reply: Jan 29, 2008 3:00 AM by Javier Diaz Soto

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
oliver lambert

Posts: 1
Nickname: olambo
Registered: Dec, 2007

chapter 4, companion objects Posted: Jan 23, 2008 12:56 AM
Reply to this message Reply
Advertisement
Its suggested to think of singleton objects as a repository for a java programmers static methods. This, would suggest that these objects start with a capital letter, like a type. Indeed, I believe that a companion object has to start with a capital letter.

The problem is, in Java I (and others) always define (singleton) objects with a lowercase letter. Perhaps a mention of any Scala style rule here, and perhaps a mention that the capitalization of the companion object is a special case?

cheers
Oliver


Javier Diaz Soto

Posts: 29
Nickname: javierbds
Registered: Sep, 2005

Re: chapter 4, companion objects Posted: Jan 29, 2008 3:00 AM
Reply to this message Reply
Agreed that the companion is an object with a special name (like constructors, main ...). In the end, syntactically you have the same mech as in java : Classname.staticmember ... Agreed it should be noted for Java programmers.

BTW, Is there an easy way to go from companion to object pool?

Related, but not necessarily in ch4 ...

The scala interpreter gives some bogus errors when using private constructor and companion object (factory methods). It says the companion cannot access the private constructor. (But I think it accepts de definitions)

I do not know if that's because it has no clear concept of the file it is loading definitions from? (as the companion object must be defined in the same file as the "companioned" (?) class).

Flat View: This topic has 1 reply on 1 page
Topic: Mutating map for Arrays? Previous Topic   Next Topic Topic: Error in Chapter 6: p119

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use