Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

dart - Null aware function invocation operator

In the same way we can have

nullableClassInstance?.method(blah)

Is there a way to do

nullableFunctionInstance?(blah)

In other words, is there an operator that checks whether a function instance is not null, if so, invoke the function all in one line?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using the call method, you can achieve what you want with:

nullableFunctionInstance?.call(blah)

There's also the apply method if you want to pass arguments.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...