Scala 2.8 中的包私有修饰符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9032631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:49:57  来源:igfitidea点击:

Package private modifier in Scala 2.8

scalapackageprivate

提问by Robin Green

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

那是怎么回事?我只能将其设置为 com.* 的包私有的,或者...?

回答by Nikita Ignatov

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)