Calling a static method from a generic constraint Dart

No, it’s not possible.

Dart static method invocations are resolved at compile-time, so it’s not possible to call them on type variables which only have a value at run-time.

If it was possible, it would be completely unsafe. Anyone can create a class C extending A which does not have a static func member and invoke concret<C>();. Since static members are not inherited, it would have to give you a run-time error, and there is nothing you can do to detect that at compile-time. That is the primary reason why it is not allowed.

Leave a Comment