Ashutosh Panda
10/20/2019, 9:57 AMimport kotlin.arrayOf as arrayOf1
var i=0
var number:Array<Int> = arrayOf(11,12,13,14,15)
var integer: MutableList<Int>(5) {0}
for(x in 0 until 5) {
integer[x]=number[x]
}
println(integer[2])
this is the changed one and error is `
error: property getter or setter expected
var integer: MutableList<Int>(5) {0}`
karelpeeters
10/20/2019, 9:58 AMval integer = MutableList(5) { 0 }
, it's a value not a type.Ashutosh Panda
10/20/2019, 10:01 AMkarelpeeters
10/20/2019, 10:03 AM:
you have to specify a type, like MutableList<Int>
. MutableList also has something constructor-like with the same name: MutableList(5) { 0 }
creates a new instance with the given elements. You can't use that as a type (after :
) because it's a value, it should go after =
.Ashutosh Panda
10/20/2019, 10:10 AMKirill Zhukov
10/20/2019, 10:13 AMMutableList(5) { 0 }
is a method call.Ashutosh Panda
10/20/2019, 10:14 AMKirill Zhukov
10/20/2019, 10:14 AMAshutosh Panda
10/20/2019, 10:15 AMKirill Zhukov
10/20/2019, 10:15 AMKirill Zhukov
10/20/2019, 10:15 AMAshutosh Panda
10/20/2019, 10:16 AMKirill Zhukov
10/20/2019, 10:17 AMMutableList
is part of the standard library which is where it is defined.karelpeeters
10/20/2019, 10:19 AMMutableList(5) { 0 }
is not actually a constructor, it's just a function and MutableList
is not actually a class it's an interface.Kirill Zhukov
10/20/2019, 10:19 AMAshutosh Panda
10/20/2019, 10:19 AMkarelpeeters
10/20/2019, 10:20 AMAshutosh Panda
10/20/2019, 10:21 AMkarelpeeters
10/20/2019, 10:22 AMAshutosh Panda
10/20/2019, 10:23 AMkarelpeeters
10/20/2019, 10:25 AMMutableList
interface looks like this: https://github.com/JetBrains/kotlin/blob/b74fe7c1c332d0475b8c4002f78c522e6c071855/core/builtins/native/kotlin/Collections.kt#L190 and the MutableList
function definition looks like this: https://github.com/JetBrains/kotlin/blob/7c77565bb8b42f45d41c7948b2d2f7f5931f7c34/libraries/stdlib/src/kotlin/collections/Collections.kt#L149