Ege Kuzubasioglu
Ege Kuzubasioglu

Reputation: 6282

Unexpected tokens (use ; to seperate expressions on the same line)

I think I messed up when I tried to write one line code in Kotlin, It seems like there is no problem but IntelliJ gives me this error here:

val cards : Array<Card> = Array(52 { i -> Card(i % 13, getSuit(i))})

Upvotes: 3

Views: 25886

Answers (1)

D3xter
D3xter

Reputation: 6435

You have two ways to fix this error.

  1. Place a , between 52 and the lambda

    val cards : Array = Array(52, { i -> Card(i % 13, getSuit(i))})

  2. Place the lambda outside of the brackets

    val cards : Array = Array(52) { i -> Card(i % 13, getSuit(i))}

Upvotes: 7

Related Questions