例如,假设我有在斯卡拉,是否有任何机制继承本地方法变量?
class Parent {
def method() {
var myvar = "test"
}
}
是否有子类中访问MYVAR任何机制?
编辑:
我试图建立在现有的语言建模的DSL。这种语言具有的功能,如
onTrade {
if (price == ...) // will compile
}
onDayStart {
if (price == ...) // will not compile
}
这是因为如果价格是一个全局变量,但也有编译时检查,以确保它只是在正确的上下文中使用。我想一种方法来模拟这将是有局部变量,可以在子类中重写。喜欢的东西
// Parent
onTrade {
var price = ...
}
// Child
onTrade {
if (price == ...)
if (somethingelse == ...) // will not compile
}
哇!为什么会有?这听起来像一个*糟糕的*功能! –
告诉我们你想做什么。我们会告诉你如何以Scala的方式来做到这一点。 – missingfaktor