Programming in Kotlin - Part 73: Challenge: | Ray Wenderlich Videos

Challenge time! Practice using properties through a hands-on challenge.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4736-programming-in-kotlin/lessons/73

I am just curious why you prefer &recommend lateinit over Optionals (https://videos.raywenderlich.com/courses/128-programming-in-kotlin/lessons/70) to avoid β€œ?” to safely access properties? as from what you suggested, even this example code in challenge looks like there is no init {} here to make sure teacherName is initialized or have a default value OR at least could have been an optional, and courseDescription could have used an elvis operator to avoid exceptions.

Given this code will throw an exception if you forget to call //course.setTeacherName(β€œMs Price”)

And try to access to courseDescription (given it needs teacherName)