问题
Is there a Dart equivalent syntax to the c# ability to specify type constraints on a generic type, e.g. in C#-like syntax where TBase is SomeType:
class StackPanel<TBase> extends Panel<TBase> where TBase : SomeType{
}
回答1:
You can specify type constraints like this :
class StackPanel<TBase extends SomeType> extends Panel<TBase> {
}
The language specification says :
A type parameter
Tmay be suffixed with anextendsclause that specifies the upper bound forT. If no extends clause is present, the upper bound isObject. It is a static type warning if a type parameter is a supertype of its upper bound. The bounds of type variables are a form of type annotation and have no effect on execution in production mode.
来源:https://stackoverflow.com/questions/18698873/dart-constraints-on-generics