添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi, can I know why is my mistake here? I also have tried to put a “?” after the “String” at line 18 to resolve this problem but it doesn’t work…

The Class header looks like this:
class Congratulations(val name: String)

You can then do a toString() method. This should remove that issue. learnerName.toString()

Like, var toLearner = Congratulations(learnerName.toString())

Looking at the documentation for readLine() https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/read-line.html

we see that it takes a String? . The ? symbol means that this string is nullable. I’m not too familiar with Kotlin but one thing I do notice is that it seems to be very strict about ambiguity (it’s that one pedantic friend everyone has). Therefore toString() removes the doubt that it will be a null value.

It probably has to do with its compiling process.