Skip to content

Instantly share code, notes, and snippets.

@keijidosha
Created December 26, 2017 05:19
Show Gist options
  • Save keijidosha/5e2ca21c38e10614da37b86c38428895 to your computer and use it in GitHub Desktop.
Save keijidosha/5e2ca21c38e10614da37b86c38428895 to your computer and use it in GitHub Desktop.

vararg

vararg にひとつだけのパラメータを渡す場合、次のように書くと 1.2 から警告が出力されるようになる。 (1.3 からはコンパイルエラーになる??)

val s = "abc,def"
println( s.split(delimiters = ','))

warning: assigning single elements to varargs in named form is deprecated

What's New in Kotlin 1.2: Deprecation: single named argument for vararg

対策: 次のように配列にし、* を付けて渡す。

val s = "abc,def"
println( s.split(delimiter = *charArrayOf(',')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment