asInstanceOf method Null safety

InterfaceType? asInstanceOf(
  1. ClassElement element
)

Return the canonical interface that this type implements for element, or null if such an interface does not exist.

For example, given the following definitions

class A<E> {}
class B<E> implements A<E> {}
class C implements A<String> {}

Asking the type B<int> for the type associated with A will return the type A<int>. Asking the type C for the type associated with A will return the type A<String>.

For a TypeParameterType with a bound (declared or promoted), returns the interface implemented by the bound.

Implementation

InterfaceType? asInstanceOf(ClassElement element);