title: Is there a better way to expose private MutableLiveData as LiveData for an ViewModel. [Android, Kotlin]
body: <p>In the following example I want to expose a List of Int like this:</p>
  
  <pre><code>    val test: LiveData&lt;List&lt;Int&gt;&gt;
          get() = _test as LiveData&lt;List&lt;Int&gt;&gt;
  
      private var _test = MutableLiveData(mutableListOf&lt;Int&gt;())
  </code></pre>
  
  <p>or in another flavor:</p>
  
  <pre><code>    private var _test2 = MutableLiveData(mutableListOf&lt;Int&gt;())
      val test2 = _test2 as LiveData&lt;List&lt;Int&gt;&gt;
  </code></pre>
  
  <p>Both are working, but there is always an Unchecked Cast.</p>
  
  <pre><code>Unchecked cast: MutableLiveData&lt;MutableList&lt;Int&gt;!&gt; to LiveData&lt;List&lt;Int&gt;&gt;
  </code></pre>
  
  <p>Is there a better way of doing this?</p>
  
  <hr>
  
  <p>Just to clarify:</p>
  
  <p>By using emptyList the usage could look like this:</p>
  
  <pre><code>class MainViewModel : ViewModel() {
      val test: LiveData&lt;List&lt;Int&gt;&gt; get() = _test
      private var _test = MutableLiveData(emptyList&lt;Int&gt;())
  
      init {
          val myPrivateList = mutableListOf&lt;Int&gt;()
          myPrivateList.add(10)
          myPrivateList.add(20)
  
          _test.value = myPrivateList
      }
  }
  </code></pre>
  
  <p>I was hoping to find a way to do this without an extra list (myPrivateList), something like this:</p>
  
  <pre><code>class MainViewModel : ViewModel() {
      val test: LiveData&lt;List&lt;Int&gt;&gt; get() = _test
      private var _test = MutableLiveData(emptyList&lt;Int&gt;())
  
      init {
          _test.value?.apply {
              add(1)
              add(2)
              add(3)
          }
      }
  }
  </code></pre>