Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wrozwad opened this issue Jun 12, 2019 · 1 comment
Closed

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

wrozwad opened this issue Jun 12, 2019 · 1 comment

Comments

@wrozwad
Copy link

wrozwad commented Jun 12, 2019

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;
}
@wrozwad
Copy link
Author

wrozwad commented Jun 13, 2019

Duplicate of #399

@wrozwad wrozwad closed this as completed Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant