Reputation: 1
Right now, I'm not working on any major projects. Just daily, bite-sized exercises and coding drills. This week = writing basic Kotlin functions. So out of my curiosity, why is Android Studio showing an "unexpected tokens" and "expecting ')' " errors for the params in my main function? The line that reads "(num1:5; num2:4)".
This is the exact format I'm seeing when I look up how to write it, but when I try to do, I keep getting errors. I even tried to copy and paste samples or snippets of code I found online, and the same thing always happens.
fun main()
{
addition(num1:5; num2:4)
}
fun addition(num1: Int, num2: Int)
{
println(num1 + num2)
}
Upvotes: 0
Views: 204
Reputation: 71
Hope this helps you to understand better! Kotlin Default Parameters
Upvotes: 0
Reputation: 708
The syntax is invalid.
Try with:
fun main() {
addition(num1= 5, num2= 4)
}
fun addition(num1: Int, num2: Int) {
println(num1 + num2)
}
Upvotes: 1