给定一些可空类型 T?
,我如何获得相应的不可空类型 T
?
例如:
T? x<T extends int?>(T? value) => value;
Type g<T>(T Function(T) t) => T;
Type type = g(x);
print(type); // Prints "int?"
现在我想获取不可为 null 的类型。我如何创建函数 convert
以便:
Type nonNullableType = convert(type);
print(nonNullableType); // Prints "int"
最佳答案
如果您有一个 T?
的实例,并且您正在尝试做一些预期类型为 T
的事情,您可以使用 use T!
dart 显示错误的地方。它不完全是从 T?
到 T
的转换,它只是执行 null 检查的快捷方式。
关于dart - 在 Dart 中,给定可空类型 `T?` ,我如何获得不可空类型 `T`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67246851/
相关文章:
perl - 什么意思 "Can' t locate object method.."在这个使用 P
asp.net-core - 如何在 ASP.NET Core 3.1 中为 Swagger 指定默
azure - 如何删除被不属于我的域锁定的 Front Door 资源
javascript - 尝试调试 javascript : "vscode listen eacc
python - 导入错误 : No module named 'typing' when tryi
reactjs - "Redundant alt attribute. Screen-readers