castInstance method

T castInstance(
  1. dynamic instance
)

Cast instance to this type, throwing if the cast fails.

This is similar to the as language operator:

// Before
final castInstance = instance as String;

// After
final castInstance = stringType.castInstance(instance);

Implementation

T castInstance(dynamic instance) => instance as T;