



Q: What happens if I try to use a property value before it’s been initialized?Ī: If you don’t initialize a property before you try and use it, you’ll get a runtime error when you run the code. In general, however, we strongly encourage you to initialize your properties. If you wanted to mark the temperament property for late initialization, for example, you’d use: lateinit var temperament: Stringĭoing so allows the compiler to compile your code. This tells the compiler that you’re aware that the property hasn’t been initialized yet, and you’ll handle it later. Is there a way of not initializing class properties in Kotlin?Ī: If you’re completely certain that you can’t assign an initial value to a property when you call the class constructor, you can prefix it with lateinit. Q: In Java, you don’t have to initialize the variables that you declare inside a class.
