Created
November 11, 2018 11:01
-
-
Save ozcanzaferayan/04cf1f993c098aa84eb19f395d644407 to your computer and use it in GitHub Desktop.
Kotlin Nedir: any tipindeki array'e string array'in atanması
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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