Unable to add type when declaring a list of string...
# getting-started
a
Unable to add type when declaring a list of strings 1. i'm not sure if i'm doing something wrong, i recall being able to declare a list type to be string with the following code below
val nameList:List<String>=listOf("Apple","Orange","Pear")
->> CODE A 2. I get the following error below "Property getter or setter expected" 3. i had to write as following
val nameList=listOf<String>("Apple","Orange","Pear")
which is fine with me, but why cant i use Code A, hope someone can advise me
k
You should add spaces. It takes the
>=
to mean greater than or equal to. The Kotlin coding conventions recommend that you should write it like this:
Copy code
val nameList : List<String> = listOf("Apple", "Orange", "Pear")
Following conventions makes it easier for others to understand your code.
a
Thanks @Klitos Kyriacou