user3382722
user3382722

Reputation: 35

IntelliJ gives error about reference in Kotlin

I'm trying to go though the Kotlin tutorial from Freecode camp, but have this issue with references.

IntelliJ complained that

  1. Unresolved reference: greeting in sayHello() in main()
  2. Unexpected tokens (use ';' to separate expressions on the same line), after "Hi"
fun sayHello(greeting:String, vararg itemsToGreet: String) {
    itemsToGreet.forEach { itemToGreet ->
        println("$greeting $itemToGreet")
    }
}

fun main() {
    val interestingThings = listOf("Kotlin", "Programming", "Comic Books")
    sayHello(greeting:"Hi", itemsToGreet:"Kotlin", "Programming", "Comic Books")
}

It seems that assigning values to params can be done only by "=", not ":"

Upvotes: 0

Views: 156

Answers (1)

y.bedrov
y.bedrov

Reputation: 6024

"greeting:" is a parameter name hint. Code should look like this:

sayHello("Hi", "Kotlin", "Programming", "Comic Books")

See how hints will be shown automatically.

Upvotes: 1

Related Questions