For example suppose I have
class Parent {
def method() {
var myvar = "test"
}
}
Is there any mechanism for accessing myvar in child classes?
Edit:
I’m trying to build a DSL modeled upon an existing language. That language has features such as
onTrade {
if (price == ...) // will compile
}
onDayStart {
if (price == ...) // will not compile
}
It is as if price is a global variable but there are compile time checks to make sure it is only used in the correct context. I was thinking one way to simulate this would be to have local variables that could be overridden in subclasses. Something like
// Parent
onTrade {
var price = ...
}
// Child
onTrade {
if (price == ...)
if (somethingelse == ...) // will not compile
}
Possible solution for your problem (though I don’t see a way to get rid of
new):