相关文章推荐
深沉的卡布奇诺  ·  verilog - Concurrent ...·  9 月前    · 
深沉的卡布奇诺  ·  A Methodology for ...·  9 月前    · 
深沉的卡布奇诺  ·  Contributors | ...·  11 月前    · 
深沉的卡布奇诺  ·  Type mismatch: ...·  11 月前    · 
侠义非凡的菠菜  ·  Python pandas ...·  3 分钟前    · 
严肃的青蛙  ·  Java维护由Collectors.grou ...·  37 分钟前    · 
欢乐的柳树  ·  基于SuperMap iObjects ...·  37 分钟前    · 
豪情万千的眼镜  ·  智能指针reset()·  2 小时前    · 
任性的筷子  ·  std::packaged_task::re ...·  2 小时前    · 

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.

 
推荐文章