getInterfaces method
Returns an array of ResolvableTypes representing the direct interfaces implemented by this type.
This method returns all interfaces that this type directly implements, not including inherited interfaces from supertypes.
Returns:
- List of ResolvableType instances representing implemented interfaces
- Empty list if no interfaces are implemented
Example:
// Assuming a class that implements multiple interfaces
class MyList<T> implements List<T>, Comparable<MyList<T>> {
// Implementation
}
final myListType = ResolvableType.forClass(MyList<String>);
final interfaces = myListType.getInterfaces();
for (final interface in interfaces) {
print(interface.resolve()?.getType());
}
// Output: List<String>, Comparable<MyList<String>>
// Useful for interface analysis
bool implementsInterface(ResolvableType type, Type interfaceType) {
final interfaces = type.getInterfaces();
return interfaces.any((iface) =>
iface.resolve()?.getType() == interfaceType ||
iface.as(interfaceType) != ResolvableType.NONE
);
}
Implementation
List<ResolvableType> getInterfaces() {
final resolved = resolve();
if (resolved == null) return _EMPTY_TYPES_ARRAY;
List<ResolvableType>? interfaces = _interfaces;
if (interfaces == null) {
final interfaceClasses = resolved.getAllInterfaces();
if (interfaceClasses.isNotEmpty) {
interfaces = interfaceClasses.map((ifc) => forType(ifc.getType(), this)).toList();
} else {
interfaces = _EMPTY_TYPES_ARRAY;
}
_interfaces = interfaces;
}
return interfaces;
}