conflicting_generic_interfaces
The {0} '{1}' can't implement both '{2}' and '{3}' because the type arguments are different.
Description
#The analyzer produces this diagnostic when a class attempts to implement a generic interface multiple times, and the values of the type arguments aren't the same.
Example
#The following code produces this diagnostic because C
is defined to
implement both I<int>
(because it extends A
) and I<String>
(because
it implementsB
), but int
and String
aren't the same type:
class I<T> {}
class A implements I<int> {}
class B implements I<String> {}
class C extends A implements B {}
Common fixes
#Rework the type hierarchy to avoid this situation. For example, you might
make one or both of the inherited types generic so that C
can specify the
same type for both type arguments:
class I<T> {}
class A<S> implements I<S> {}
class B implements I<String> {}
class C extends A<String> implements B {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。