-
Notifications
You must be signed in to change notification settings - Fork 213
Unable to specify interfaces or mixins as type arguments #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The bound The same thing with (The first class So, what is the problem that you are trying to solve, and that you cannot? Dart currently gives you no way to put multiple bounds on a single type variable. |
Would #65 be a possible solution? |
Java uses |
I don't think #65 makes much difference here, because that proposal is about being able to declare aliases of types in general, rather than only being able to declare aliases of function types (which were needed way back when function types couldn't be written inline at all). But we probably won't introduce intersection types as a syntactic special case that you can only use in a type alias, and if we want to introduce a special case of intersection types (that is: only for type variable bounds) then it's actually even less likely that it would help to go via type aliases (because we would then have to have very special rules about the usage of type aliases, to enforce that no intersection type occurs anywhere except as a type variable bound). |
What if I need a method, that operates on both:
|
Dart doesn't currently offer statically safe ways to use methods that aren't guaranteed to be there, and you can't specify a type that has both Here are some workarounds:
void test1(Object data) {
if (data is! TypedData || data is! List<int>) throw "Wrong type";
final typed = data as TypedData; // unnecessary, see below
final list = data as List<int>;
print(typed.buffer);
print(list.asMap);
}
void test3(dynamic data) {
if (data is! Int16List || data is! Int32List) throw "Wrong type";
print(data.buffer);
print(data.asMap);
} Regarding intersection types, it's interesting that in the first example, you'll notice that Dart actually infers that Also see #1612, although be sure to read #1612 (comment) and #1612 (comment). |
Thanks @lrhn. |
The text was updated successfully, but these errors were encountered: