If I try
private[com.company.foo] def bar(xml: XmlPath) = {
I get
[error] ... ']' expected but '.' found. [error] private[com. [error] ^
What's with that? I can only make it package-private to com.*, or...?
In Scala,private[this] is object private,which makes sure that any other object of same class is unable to access private[this] members.
Package in Scala is a mechanism to encapsulate a group of classes, sub packages, traits and package objects. It basically provides namespace to put our code in a different files and directories. Packages is a easy way to maintain our code which prevents naming conflicts of members of different packages.
In Scala, members that are private are accessible not only inside the class itself, but also in the class' companion object (and vice versa: a private member in an object is accessible also in the object's companion class).
You can only define the enclosing package, within which the code is defined:
package com.company.foo class Bar{ private[foo] def bar(xml: XmlPath) }
and if you want to set it to company:
private[company] def bar(xml: XmlPath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With