Why do I get this? Kotlin: Type mismatch: inferred type is String? but String was expected
问题 When I try to run this code: fun main() { val input: String = readLine() val outputs = input.toCharArray() for (i in 0 until input.length) { print("${outputs[i]}${outputs[i]}") } } I get this Error:(2, 25) Kotlin: Type mismatch: inferred type is String? but String was expected. How do I fix that? 回答1: The readLine() function returns a String? (nullable String). Return the line read or null if the input stream is redirected to a file and the end of file has been reached. There is no end of