Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package private modifier in Scala 2.8

Tags:

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...?

like image 933
Robin Green Avatar asked Jan 27 '12 11:01

Robin Green


People also ask

What is private this in Scala?

In Scala,private[this] is object private,which makes sure that any other object of same class is unable to access private[this] members.

What are different packages in Scala?

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.

What is private class in Scala?

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).


1 Answers

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) 
like image 186
Nikita Ignatov Avatar answered Oct 03 '22 12:10

Nikita Ignatov