title: Using lateinit properties in constructor in kotlin
body: <p>How can I use lateinit properties in my class constructor:</p>
  
  <p>I have a spring component that I use to setup and access a third party library like so:</p>
  
  <pre><code>@Service
  class LibProxy {
  
      @Value("\${lib.someProperty}")
      private lateinit var someProperty: String
  
      final var lib: Lib
  
      init {
          lib = Lib(someProperty)
      }
  }
  </code></pre>
  
  <p>This gives a </p>
  
  <pre><code>kotlin.UninitializedPropertyAccessException: lateinit property someProperty has not been initialized
  </code></pre>
  
  <p>How is this supposed to be done?</p>
  
  <p>I would like to avoid constructs like so:</p>
  
  <pre><code>@Service
  class LibProxy {
  
      @Value("\${lib.someProperty}")
      private lateinit var someProperty: String
  
      private var lib: Lib? = null
  
      getLib(): Lib {
          if (lib == null) {
              lib = Lib(someProperty)
          }
          return lib ?: Lib(someProperty)
      }
  }
  </code></pre>