Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

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.

like image 672
MSmedberg Avatar asked Nov 27 '25 13:11

MSmedberg


1 Answers

No, there is no such modifier.

like image 53
Alexey Romanov Avatar answered Nov 30 '25 04:11

Alexey Romanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!