Why can't I access private class methods in the class's companion object in Scala?

I'm working on a homework assignment for my object oriented design class, and I'm running into trouble with Scala's companion objects. I've read in a few places that companion objects are supposed to have access to their companion class's private methods, but I can't seem to get it to work. (Just as a note, the meat of the assignment had to do with implementing a binary search tree, so I'm not just asking for answers...)

I have an object that is supposed to create an instance of my private class, BstAtlas (Bst is also defined in the Atlas object, took it out for clarity):

object Atlas {                                             
  def focusRoom(newRoom:Room,a:Atlas):Atlas = a.helpFocusRoom(newRoom);

  abstract class Atlas {
    ...
    protected def helpFocusRoom(n:Room):Atlas;
    ...
  }

  private class BstAtlas(bst:Bst) extends Atlas {
    ...
    protected def helpFocusRoom(newRoom:Room):Atlas = ...
       // uses some of bst's methods
    ...
  }
}

But when I go to compile, I get the following error:

Question23.scala:15: error: method helpFocusRoom cannot be accessed in Atlas.Atlas a.helpFocusRoom(newRoom);

The function helpFocusRoom needs to be hidden, but I don't know how to hide it and still have access to it inside of the companion object.

Can anyone tell me what I'm doing wrong here?

Answers


The problem is that classes and companion objects can't be nested like that. To define a companion object, you need to define the class outside of the object's body but in the same file.


Need Your Help

iOS : Slow searching in SQLite database

iphone objective-c ios xcode ipad

I have created a dictionary app with SQL data base , but the problem is when users search a word in UISearchBar the searching process is very slow ! why this happens ? here is my code :

GAE JSP and Facebook-api-java iframe fb_sig_* param

google-app-engine jsp facebook http-headers

I am building facebook app using iFrame (using Google App Engine Java,JSP and Facebook-api-java), and when Facebook calls back to my website, I expect to get the fb_sig_* request params for the iFr...