Last active
November 7, 2015 18:27
-
-
Save dmcg/c66db992c4b463a72042 to your computer and use it in GitHub Desktop.
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
| 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