English 中文(简体)
鉴定一种内壳体的方法,使其从外部是私人的,但可以从内部获得
原标题:Qualifying an inner trait s method so that it is private from the outside but accessible from the inside

我要限定一种内地海峡的方法,只有外壳的子流能进入。 例如:

trait Tree[A] {
  trait TNode {
    final def prevOption: Option[TNode] = Option(prev)
    protected[Tree] def prev: TNode // !
  }

  def test(n: TNode): Option[TNode] = Option(n.prev)
}

我如何修改<代码>前的限定词,以便:do 汇编:

trait TreeImpl[A] extends Tree[A] {
  def test2(n: TNode): Option[TNode] = Option(n.prev)
}

http://www.strong.org。 汇编:

def test3[A](t: Tree[A]#TNode) = t.prev

(也就是说,公共<代码>def prev:TNode不是选择。)

最佳回答

这似乎是不可能的。

可能的工作是树上的一种受保护的取用方法,如(我消除了某些障碍,使代码更加清晰):

trait Tree {
    trait TNode {
        private[Tree] def prev : TNode
    }
    protected final def prevAccessor(n: TNode) = n.prev
    def test( n: TNode ) = n.prev
}

trait TreeImpl extends Tree {
    def test2( n: TNode ) = prevAccessor(n)
}
问题回答

暂无回答




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签