Difference In Kotlin list declaration? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Difference In Kotlin list declaration?

val list1= listOf(1,2,3) val list2= listOf<Int>(1,2,3) Is there any difference between those 2 lists? Can we omit <Int> ?🤔

20th May 2021, 8:03 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
1 Answer
+ 4
Muhd Khairul Amirin In 2nd declaration your elements should be of Int type only And in 1st declaration data can be anything. See here li2 will give error but li1, li3 and li4 will not. Same we can see for other data type https://code.sololearn.com/cC3gV5PNFG3i/?ref=app
20th May 2021, 8:10 AM
A͢J
A͢J - avatar