title: Kotlin lazy property depending on another property initialized in init
body: <p>I have the following class in Kotlin:</p>
  
  <pre><code>class Example {
      val name: String
  
      val lazyVar: String by lazy {
          name + " something else"
      }
  
      init {
          name = "StackOverflow"
      }
  }
  </code></pre>
  
  <p>I get the following error when I use <code>name</code> in the lazy initialize block of <code>lazyVar</code> (even though <code>name</code> is initialized in the <code>init</code> block) :</p>
  
  <blockquote>
    <p>Variable 'name' must be initialized</p>
  </blockquote>
  
  <p>A solution is to initialize the variable in another method:</p>
  
  <pre><code>class Example {
      val name: String
  
      val lazyVar: String by lazy {
          initLazyVar()
      }
  
      init {
          name = "StackOverflow"
      }
  
      private fun initLazyVar(): String {
          return name + " something else"
      }
  }
  </code></pre>
  
  <p>This technique works but is there a way to keep the compacity of the inline lazy block instead of relying on an external function?</p>