title: Kotlin: Check if lazy val has been initialised
body: <p>Is there a way to tell if a lazy val has been initialised in Kotlin without initialising it in the process?</p>
  
  <p>eg if I have a lazy val, querying if it is null would instantiate it</p>
  
  <pre><code>val messageBroker: MessageBroker by lazy { MessageBroker() }
  if (messageBroker == null) {
      // oops
  }
  </code></pre>
  
  <p>I could potentially use a second variable, but that seems messy.</p>
  
  <pre><code>private var isMessageBrokerInstantiated: Boolean = false
  val messageBroker: MessageBroker by lazy {
      isMessageBrokerInstantiated = true
      MessageBroker()
  }
  
  ...
  
  if (!isMessageBrokerInstantiated) {
      // use case
  }
  </code></pre>
  
  <p>Is there some sexy way of determining this, like <code>if (Lazy(messageBroker).isInstantiated())</code>?</p>
  
  <p>Related (but not the same): <a href="https://stackoverflow.com/questions/37618738/how-to-check-if-a-lateinit-variable-has-been-initialized">How to check if a &quot;lateinit&quot; variable has been initialized?</a></p>