```import kotlin.arrayOf as arrayOf1 var i=0 var n...
# announcements
a
Copy code
import 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
Copy code
`
error: property getter or setter expected
var integer: MutableList<Int>(5) {0}`
k
It should be
val integer = MutableList(5) { 0 }
, it's a value not a type.
a
Thanks but please explain what went wrong
k
After the
:
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
=
.
a
Sir I beginner I know what is constructor ("I know C++) but I cannot understand your answer from second line could you please explain in easy language
k
MutableList(5) { 0 }
is a method call.
a
where is constructor definition and the corresponding class
k
In the class definition. If you use IDE you can jump to it.
a
pardon me I can't understand
k
For basic syntax I highly recommend checking out official kotlin reference https://kotlinlang.org/docs/reference/basic-syntax.html, it's quite nice and covers everything you need to start, unless you have specific questions?
What specifically?
a
In C++ there is constructor definition inside a class but where is the class here
k
It's not different in Kotlin.
MutableList
is part of the standard library which is where it is defined.
k
Err careful.
MutableList(5) { 0 }
is not actually a constructor, it's just a function and
MutableList
is not actually a class it's an interface.
1
k
Yeah, just looked it up lol
a
interface?
k
An interface is like an abstract class in C++ only it's not allowed to contain any state.
a
When you say```MutableList(5) {0}``` does the function creates an list of 5 element size
k
Yes! If I remember correctly array sizes are sometimes part of the type in C++, in Kotlin that's not the case.
a
Thanks for your support @Kirill Zhukov and @karelpeeters
k