How to declare a generic operator in strong Dart mode?

Dart allows me to declare common methods, for example. T first<T>(List<T> ts). But how can I declare a generic type for methods that are operators, for example operator |? Is there any syntax for this (and documented it somewhere)?

+4
source share
2 answers

Dart operators cannot be shared.

The main reason is the lack of syntax to provide type. Using a generic method, you can call it as o.foo<int>(...)to explicitly pass a type argument. Cannot be placed <int>in a statement (no, we do not want to allow x+<int>42, which just reads horribly!)

, , . , ( ), .

+3

Source: https://habr.com/ru/post/1689632/


All Articles