I want to be able to specify a generic type for a particular class method in dart:
class Foo{
// Dart doesn't support declaration of type parameters in methods
void bar<T>(T a){}
}
I know I can specify generic types on classes but why not methods?
This is one of the oldest open issues in Dart.
https://code.google.com/p/dart/issues/detail?id=254
The issue contains a longer discussion about why this should/should not be implemented.
You can use type parameters on methods when you declare them on the type though
class Foo<T>{
void bar(T a){}
T bar(a){}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.