我目前正在为 Android ( https://github.com/bertderbecker/scalandroid ) 开发一个小的 scala DSL。
val drawerLayout = new SDrawerLayout {
openDrawerFrom = SGravity.LEFT
fitsSystemWindows = true
navigationView = new SNavigationView {
println(parent) //None - the parent of the drawerlayout
// I want that the parent is the drawerlayout
layout = SLayout.NAVI_HEADER_DEFAULT
fitsSystemWindows = true
}
}
如何告诉 SNavigationView 使用 SDrawerLayout 作为其父级,而不是 DrawerLayout 的父级?
所以,更一般地说,我想要一个类 foo (0) ,它将 foo (-1) 作为隐式参数,并且您可以在其中定义一个 foo (+1),它将从作为隐式参数开始。
所以 foo 是“递归的”。
我想要的是:
class foo()(implicit parent: foo) {
parent = this
val f = new Foo { //takes this as its parent
}
}