Assemblyscript 类继承 - 类型转换
有没有一种方法可以从基类转换为派生类?
class A{}
class B extends A{}
const b = new B()
const a:A = b //casts to base class ok
const b2:B = a //Error: Type 'A' is not assignable to type 'B'
Is there a way to cast from a base class into a derived one?
class A{}
class B extends A{}
const b = new B()
const a:A = b //casts to base class ok
const b2:B = a //Error: Type 'A' is not assignable to type 'B'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来在 Assemblyscript 中这称为向上转换。
目前实现它的唯一方法是使用
a as B
语法。目前不支持其他语法
Looks like in Assemblyscript this is called upcasting.
Currently the only way to achieve it is by using
a as B
syntax.Other syntax is currently not supported