Description
When defining a generic class which has a generic parameter that should extend a type that in turn is a generic class, you now have to add all the generic parameters of the second type also in the parameter list of the first class to be able to access those type parameters. This is cumbersome and seems unnecessary.
For example, the following definition:
class A<T extends B<U,V,W>,U,V,W> {
U u;
}
could be simplified to:
class A<T extends B<U,V,W>> {
U u;
}
I don't think that allowing this syntax would have any implications or breaking changes, it would simply be syntactic sugar for the first syntax.
A concrete example is the following situation. Suppose you are using the BLoC pattern and have a base class for blocs BaseBloc
which has a generic parameter that defines the state:
abstract class BaseBloc<S> {
Stream<S> get state;
}
and a base class for components in AngularDart
(or widgets or flutter
):
// in the current syntax the extra type parameter S is still necessary
class BaseBlocComponent<T extends Bloc<S>/*,S*/> {
final T bloc;
S currentState;
BaseBlocComponent(this.bloc) {
bloc.stream.listen((state)=>currentState = state);
}
}
You could now implement a concrete state, bloc and component:
class MyState {}
class MyBloc extends BaseBloc<MyState> {
}
class MyComponent extends BaseBlocComponent<MyBloc/*,MyState*/> {
// The extra MyState parameter is unnecessary, because it is implied by the type of MyBloc
// Moreover, you need to know which classes MyBloc extends in order to be able to set the
// correct value for the second type parameter
}