Skip to content

Instantly share code, notes, and snippets.

@dmcg
Last active November 7, 2015 18:27
Show Gist options
  • Save dmcg/c66db992c4b463a72042 to your computer and use it in GitHub Desktop.
Save dmcg/c66db992c4b463a72042 to your computer and use it in GitHub Desktop.
package speed
import org.junit.Test
import kotlin.test.assertEquals
class KotlinArrayCastTest {
val strings = arrayOfNulls<String>(10000)
@Test(expected = NullPointerException::class)
fun dont_fill() {
val actuallyNotStrings : Array<String> = strings as Array<String> // IntelliJ warns "This cast can never succeed"
// but it does
}
@Test
fun fill() {
strings.fill("hello")
val definitelyStrings : Array<String> = strings as Array<String>
assertEquals("hello", definitelyStrings[0])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment