unnecessary_cast
Details about the 'unnecessary_cast' diagnostic produced by the Dart analyzer.
Unnecessary cast.
Description
#The analyzer produces this diagnostic when the value being cast is already known to be of the type that it's being cast to.
Example
#
The following code produces this diagnostic because n is already known to
be an int as a result of the is test:
dart
void f(num n) {
if (n is int) {
(n as int).isEven;
}
}
Common fixes
#Remove the unnecessary cast:
dart
void f(num n) {
if (n is int) {
n.isEven;
}
}
Was this page's content helpful?
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.