Out (Generics)

Specifies that a type parameter is covariant.

Instructions

Covariance lets you use a child class of the class specified by a generic parameter. This lets classes that implement variant traits convert automatically. See Covariance and Contravariance for more information.

Limits

You can use the modifier Out with generic traits and events.

In a generic trait, you can declare a type parameter as covariant if you obey the instructions that follow:

Examples

' Covariant trait.
Trait TCovariant[Out T]
End Trait

' Extending covariant trait.
Trait TExtCovariant[Out T] Does TCovariant[T]
End Trait

' Implementing covariant trait.
Class Sample[T] Does TCovariant[T]
End Class

Var parent As TCovariant[CParent] = CSample[CParent]
Var child As TCovariant[CChild] = CSample[CChild]

' You can assign child to parent because
' the TCovariant trait is covariant.
parent = child

Applies to

See also