0
Why this err is occurring? And how to solve it?
fun man(a:Int):Int{ if(a>3){ return a } } fun main(args: Array<String>) { print(man(6)) }
2 Respostas
+ 3
If a is not greater than 3 the function does not return a value, but the return type says Int.
You need an else part that returns some default value, or make the return type nullable and return null.
+ 2
fun man(a:Int):Int{
if(a>3) return a
return 0 // A 'return' expression required in a function with a block body
}
fun main(args: Array<String>) {
print(man(6))
}