Hey! I have come across an error in the IntelliJ I...
# getting-started
w
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
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
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
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
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
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
I think the default font is very reasonable. but once custom themes come into play yea things could get confusing
l
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
yea
l
You don’t need to type it in your file either. The IDE should show this itself.
w
Yea! i understand that now. thanks 👍