Is it possible to create and return an instance of This?
The following looks good but results in the compile error Cannot return sys::This? as wotever::A This
class A {
This stuff() {
return typeof.make() as This
}
}
class B : A {}
KevinKelleyWed 22 Feb 2012
This is the dynamic type, you need to give it a static type too...
class A {
This dup() {
typeof.make as A
}
override Str toStr() { "A" }
}
class B : A {
override Str toStr() { "B" }
}
class test {
Void main() {
b := B()
x := b.dup
echo(x)
}
}
prints B. Works as long as the subclass has a no-args constructor, handy for cloning.
SlimerDude Wed 22 Feb 2012
Is it possible to create and return an instance of
This
?The following looks good but results in the compile error
Cannot return sys::This? as wotever::A This
KevinKelley Wed 22 Feb 2012
This
is the dynamic type, you need to give it a static type too...prints
B
. Works as long as the subclass has a no-args constructor, handy for cloning.SlimerDude Wed 22 Feb 2012
Okay, sweet!
Cheers! - Steve.