https://kotlinlang.org logo
#getting-started
Title
# getting-started
w

Will_505

07/07/2022, 7:26 PM
Hey! I have come across an error in the IntelliJ IDE in Main.kt the tutorial i am following is telling me to declare my functions like so but i am getting issues with the compiler. the code:
Copy code
fun sayHello(itemToGreet:String) = println("Hello $itemToGreet")

fun main() {
    sayHello(itemToGreet: "Kotlin")
    sayHello(itemToGreet: "World")

}
The error:
l

Landry Norris

07/07/2022, 7:27 PM
You need to write
itemToGreet = "Kotlin"
when calling sayHello
Same with the second call.
Copy code
fun sayHello(itemToGreet: String) = println("Hello $itemToGreet")

fun main() {
    sayHello(itemToGreet = "Kotlin")
    sayHello(itemToGreet = "World")

}
The parameter name is also not required, unlike in Swift. You can just write
Copy code
fun sayHello(itemToGreet:String) = println("Hello $itemToGreet")

fun main() {
    sayHello("Kotlin")
    sayHello("World")

}
👍 1
w

Will_505

07/07/2022, 7:33 PM
ah i see. ok interesting. I will try to perform that change when going through the video tutorials then. the video is from 2019 so maybe its outdated
Thank you!
l

Landry Norris

07/07/2022, 7:36 PM
Interesting. I don’t think Kotlin’s ever supported (name: value) syntax for parameters. You do use (name: Type) when defining the function and (name = value) syntax when calling with explicit parameter names.
w

Will_505

07/07/2022, 7:40 PM
it was the IDE adding in some fancy syntax and because of the font from the instructor i assumed they had typed it out. that's why. because im new i just got confused
image.png
Their syntax appears much larger and looks like its been typed out
*font, not syntax
l

Landry Norris

07/07/2022, 7:42 PM
I see. It makes sense that the inlay there could be confusing. I wonder if JetBrains has considered this. It could confuse a lot of people new to Kotlin.
w

Will_505

07/07/2022, 7:43 PM
I think the default font is very reasonable. but once custom themes come into play yea things could get confusing
l

Landry Norris

07/07/2022, 7:44 PM
That looks like it’s an IDE inlay. It’s not part of the actual code (there’s no text where it says ‘itemToGreet:’ in the file). It’s just a nice IDE feature that hints what the name is.
w

Will_505

07/07/2022, 7:44 PM
yea
l

Landry Norris

07/07/2022, 7:44 PM
You don’t need to type it in your file either. The IDE should show this itself.
w

Will_505

07/07/2022, 7:45 PM
Yea! i understand that now. thanks 👍
5 Views