MSmedberg
MSmedberg

Reputation: 481

Can a Scala object be visible to only those objects in the same file?

Is there an access modifier [Edit: or an idiomatic workaround which achieves the same thing] which will allow a Scala name/object to be visible to all the code in the same file, but not the whole package the file is part of?

package org.example.foo

private object SharedStuff {
  val bar = 0
}

class Foo {
  def apply(x: Int): String = ... something involving SharedStuff.bar ...
}

class Fuz {
  def fuzz(t: String): Int = ... something else involving SharedStuff.bar ...
}

In its current state, the object SharedStuff will be visible to all code in package foo. I'd like it to be visible to the classes Foo and Fuz only, without making an explicit subpackage to enclose this file.

Upvotes: 3

Views: 855

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170735

No, there is no such modifier.

Upvotes: 4

Related Questions