fun main(){
println("${updateWeather(10)}")
}
fun updateWeather(degrees: Int) {
val (description : String, color: Int) = when {
degrees < 10 -> "cold" to BLUE
degrees < 25 -> "milt" to ORANGE
else -> "hot" to RED
}
}
// output
Type inference for control flow expression failed. Please specify its type explicitly.
Unresolved reference: BLUE
Unresolved reference: ORANGE
Unresolved reference: RED
You need to specify the constants. The compiler doesn’t know what BLUE, ORAGNE or RED is.
1 Like
fun main() {
println(“${updateWeather(7)}”)
}
enum class Color {
BLUE, ORANGE, RED
}
fun updateWeather(degrees: Int) {
val (description, color) = when {
degrees < 5 → Pair(“cold”, Color.BLUE)
degrees < 23 → Pair(“mild”, Color.ORANGE)
else → Pair(“hot”, Color.RED)
}
}
error log
no main manifest attribute, in application.jar