array init

This commit is contained in:
Alex Tkachman
2011-09-30 18:05:36 +03:00
parent 6bfaac9c34
commit 3e388cc4a4
12 changed files with 105 additions and 19 deletions
@@ -1,5 +1,5 @@
fun box() : String {
val a = Array<Int> (5)
val a = Array<Int> (5, {0})
var i = 0
var sum = 0
for(el in 0..4) {
@@ -0,0 +1,14 @@
fun box() : String {
val a = IntArray (5)
var i = 0
var sum = 0
for(el in 0..4) {
a[i] = i++
}
for (el in a) {
sum = sum + el
}
if(sum != 10) return "a failed"
return "OK"
}
@@ -44,7 +44,7 @@ fun box() : String {
}
if(sum != 15) return "c4 failed"
val a : Array<Int> = Array<Int> (5)
val a : Array<Int> = Array<Int> (5, {0})
for(el in 0..4) {
a[i] = i++
}
+2 -2
View File
@@ -5,7 +5,7 @@ fun main(args: Array<String>?) {
//do not compile
System.out?.println(fff<Unit>(())) //do not compile
System.out?.println(id<Unit>(y)) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0),{(e : Int) : Unit => }))) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0,{0}),{(e : Int) : Unit => }))) //do not compile
}
class A<T>()
@@ -30,7 +30,7 @@ fun almostFilter(array: Array<Int>, action: fun(Int): Int) {
}
fun box() : String {
val a = Array<Int> (3)
val a = Array<Int> (3,{-1})
a[0] = 0
a[1] = 1
a[2] = 2
+1 -1
View File
@@ -5,7 +5,7 @@ fun t1 () {
}
fun t2 () {
val a2 = Array<Int>(1)
val a2 = Array<Int>(1,{0})
a2[0] = 0 //ok
var i = a2[0] //ok
}
+1 -1
View File
@@ -28,7 +28,7 @@ fun box() : String {
println(b.a[0])
val c = List<Array<Int>>(1)
c.a[0] = Array<Int>(4)
c.a[0] = Array<Int>(4,{-1})
println(c.a[0].size)
val e = List<Int>(5)