我想将自定义类 A 的实例强制转换为 int。隐式强制转换运算符的语法是什么? (我以为我记得有这样的功能,但我在网上找不到它)
int a = (new A());
您还可以使用as
帮助告诉工具“不,真的,将此对象视为此类型”。
一个很好的例子是当你必须处理 dart:html 时querySelector()
功能。
FormElement form = querySelector('#sign-up') as FormElement;
在上面,返回的对象querySelector('#sign-up')
检查它是否确实是 FormElement 的实例。
了解更多信息,请访问https://www.dartlang.org/docs/dart-up-and-running/ch02.html#operators https://www.dartlang.org/docs/dart-up-and-running/ch02.html#operators
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)