Calling a static method from a generic constraint Dart

后端 未结 1 1742
遥遥无期
遥遥无期 2020-12-11 07:50

I\'m trying to call a static method from a generic type I receive. Is that even possible?

Furthermore, I apply a Type constraint in order to only manipulate the obje

相关标签:
1条回答
  • 2020-12-11 08:14

    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.

    0 讨论(0)
提交回复
热议问题