Dart, why I can not use generics according to the method

I want to be able to specify a generic type for a particular class method in the droid:

class Foo{
  // Dart doesn't support declaration of type parameters in methods
  void bar<T>(T a){}
}

I know that I can specify generic types in classes, but why not methods?

+4
source share
1 answer

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 of why this / should not be implemented.

You can use type parameters for methods when you declare them in a type, but

class Foo<T>{
  void bar(T a){} 
  T bar(a){}
}
+4
source

All Articles