Dart, constraints on Generics?
Asked Answered
A

1

34

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{

}
Antimonous answered 9/9, 2013 at 13:3 Comment(0)
S
44

You can specify type constraints like this :

class StackPanel<TBase extends SomeType> extends Panel<TBase> {
}

The language specification says :

A type parameter T may be suffixed with an extends clause that specifies the upper bound for T. If no extends clause is present, the upper bound is Object. 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.

Samale answered 9/9, 2013 at 13:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.