Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tw-Frey/08c30e77bc3e2ad499aa982d0ade29ac to your computer and use it in GitHub Desktop.
Save tw-Frey/08c30e77bc3e2ad499aa982d0ade29ac to your computer and use it in GitHub Desktop.
Safe call on a non-null receiver will have nullable type in future releases.

Safe call on a non-null receiver will have nullable type in future releases.

Right now safe call on non nullable receiver has not null type:

"hello"?.length has type Int

In future releases all safe calls will have nullable type:

"hello"?.length will have type Int?

用意:

  1. 不要濫用 nullable type and safe call(?.) : 如果確定是 non-null object 請直接用 dot call 提取 property 或 呼叫 function
  2. safe call 性質傳遞 : 不論是否 non-null object 用 safe call 提取 property 或 function return 也直接感染 nullable type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment