Skip to content

Instantly share code, notes, and snippets.

@ezura
Created June 26, 2017 04:21
Show Gist options
  • Select an option

  • Save ezura/2ff6d3f8e84f6f51f72917abc499f0bb to your computer and use it in GitHub Desktop.

Select an option

Save ezura/2ff6d3f8e84f6f51f72917abc499f0bb to your computer and use it in GitHub Desktop.
kotlin での optional のやつ見て思ったこと。エラーメッセージしっかりしててくれた。「inout つけた場合に"書き換え(in)"も許可する必要があるので不変じゃないといけなくなる」という認識であってるかな…
func f(_ v: Any?) {}
func f_inout(_ v: inout Any?) { /* v = nil */ }
var v: Any = 1
// OK
f(v)
// ❗️error: cannot pass immutable value as inout argument: implicit conversion from 'Any' to 'Any?' requires a temporary
//f_inout(&v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment