added a demonstration of how Kotlin currently handles nullable collections on for loops - by throwing NPEs

This commit is contained in:
James Strachan
2012-02-28 09:08:39 +00:00
parent 9ba1dbf98a
commit 84327d06c1
2 changed files with 48 additions and 0 deletions
@@ -0,0 +1,20 @@
package test.language
import junit.framework.TestCase
import java.util.Collection
import stdhack.test.*
class NullableCollectionsTest : TestCase() {
fun testIterateOverNullCollectionsThrowsNPE() {
val c: Collection<String>? = null
// TODO currently this will throw a NPE
// should it either be a compile error or handle nulls gracefully?
failsWith<NullPointerException> {
for (e in c) {
println("Hey got $e")
}
}
}
}