Skip to content

Add "Safe" (nullable) cast operator as? #399

Open
@wrozwad

Description

@wrozwad

It'll be a little enhancement but so much pleasant one :)

Kotlin and Swift has something like Safe casting with as? operator. It gives an opportunity to casting with null fallback if cast can't be performed:

void someFunction(dynamic arg) {
  // we could has something like
  final classVariable = (arg as? SomeClass)?.someValue;
  
  // in place of
  final classVariable = arg is SomeClass ? arg.someValue : null;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    small-featureA small feature which is relatively cheap to implement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions