Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created November 11, 2018 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozcanzaferayan/04cf1f993c098aa84eb19f395d644407 to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/04cf1f993c098aa84eb19f395d644407 to your computer and use it in GitHub Desktop.
Kotlin Nedir: any tipindeki array'e string array'in atanması
// Aşağıdaki gibi bir array atama fonksiyonumuz olduğunu düşünelim
fun copy(from: Array<Any>, to: Array<Any>) {
assert(from.size == to.size)
for (i in from.indices)
to[i] = from[i]
}
/*
* main metodunda int ve Any tipinde iki array var.
* Any tipindeki array'e, int array'inin atanması derleme zamanı hatası verir.
*/
fun main(args: Array<String>) {
val ints: Array<Int> = arrayOf(1, 2, 3)
val any = Array<Any>(3) { "" }
copy(ints, any)
// Type mismatch: inferred type is Array<Int> but Array<Any> was expected
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment