I was told by someone to make the companion object function private and import the companion object to the class and then access the function in the class.
The following code does not work in the repl.
Example:
object Foo {
private def bar(i: Int): Boolean = i == 5
}
class Foo{
import Foo._
bar(0)
}
object Foo {
private def bar(i: Int): Boolean = i == 5
}
class Foo{
import Foo._
Foo.bar(0)
}
scala> object Foo {
| private def bar(i: Int): Boolean = i == 5
| }
defined object Foo
scala>
scala> class Foo{
| import Foo._
|
| bar(0)
| }
<console>:15: error: not found: value bar
bar(0)
^
scala>
scala> object Foo {
| private def bar(i: Int): Boolean = i == 5
| }
defined object Foo
scala>
scala> class Foo{
| import Foo._
|
| Foo.bar(0)
| }
<console>:15: error: method bar in object Foo cannot be accessed in object Foo
Foo.bar(0)
^