I'm studying Kotlin on my own, but I don't understand this part, so I'm asking a question
var operPriorityMap: Map<Char, Int> = mapOf(
'(' to 0,
'+' '+' to 1,
'-' '-' to 1,
'*' '*' to 2,
'/' '/' to 2)
var tokenPriority: Int = operPriorityMap.get('+')
var topPriority: Int = operPriorityMap.get('*')
if(tokenPriority > topPriority){
//
}
The message below appears in the operPriorityMap.get() section.
Type mismatch. Required:Int Found:Int?
I think it's the same Int type, but I don't know why it's not working. I can't even say to Int(), but is the grammar wrong?
kotlin map get
Check the nullable part of the coat line.
var tokenPriority: Int? = operPriorityMap.get('+')
var topPriority: Int? = operPriorityMap.get('*')
In Kotlin, there is a distinction between a null type and a non-null type.
A ? is nullable.
© 2024 OneMinuteCode. All rights reserved.