title: What do I get the error Smart cast to 'HomeViewModel' is impossible when I use data binding in Android Studio?
body: <p>I binding <code>HomeViewModel</code> to layout.xml using  <code>&lt;variable name=&quot;aHomeViewModel&quot;type=&quot;info.dodata.voicerecorder.viewcontrol.HomeViewModel&quot; /&gt;</code></p>
  <p>I get the following error when I run the code.</p>
  <p><em>Smart cast to 'HomeViewModel' is impossible, because 'binding.aHomeViewModel' is a mutable property that could have been changed by this time</em></p>
  <p>I think that <code>binding.aHomeViewModel.delete(binding.amVoice)</code> cause the error, how can I fix it?</p>
  <p><strong>VoiceAdapters.kt</strong></p>
  <pre><code>class VoiceAdapters (private val aHomeViewModel: HomeViewModel):
          ListAdapter&lt;MVoice, VoiceAdapters.VoiceViewHolder&gt;(MVoiceDiffCallback()) {
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VoiceViewHolder {
          return VoiceViewHolder(
              LayoutVoiceItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
          )
      }
  
      override fun onBindViewHolder(holder: VoiceViewHolder, position: Int) {
          val aMVoice = getItem(position)
          holder.bind(aHomeViewModel, aMVoice)
      }
  
      class VoiceViewHolder (private val binding: LayoutVoiceItemBinding):
            RecyclerView.ViewHolder(binding.root) {
  
          init {
              setControl()
          }
  
          private fun navigateToDetail( view: View,  aMVoice: MVoice )
          {
              val direction = FragmentHomeDirections.actionHome2Detail(aMVoice)
              view.findNavController().navigate(direction)
          }
  
          fun bind(aHomeViewModel: HomeViewModel, aMVoice: MVoice){
              binding.amVoice=aMVoice
              binding.aHomeViewModel=aHomeViewModel
              binding.executePendingBindings()
          }
  
          fun setControl(){              
              binding.btnDelete.setOnClickListener {
                  binding.amVoice?.let {
                    binding.aHomeViewModel?.let {
                       binding.aHomeViewModel.delete(binding.amVoice)  //I think it cause error.
                    }
                }
              }
          }
      }
  
  }
  
  
  class MVoiceDiffCallback : DiffUtil.ItemCallback&lt;MVoice&gt;() {
     ...
  }
  </code></pre>
  <p><strong>HomeViewModel.kt</strong></p>
  <pre><code>class HomeViewModel(private val mDBVoiceRepository: DBVoiceRepository) : ViewModel() {
      ...
      
      fun delete(aMVoice: MVoice){
          viewModelScope.launch {
              mDBVoiceRepository.deleteVoice(aMVoice)
          }
      }
  
  }
  </code></pre>
  <p><strong>layout.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  
  &lt;data&gt;
      &lt;variable name=&quot;aMVoice&quot;
          type=&quot;info.dodata.voicerecorder.model.MVoice&quot;  /&gt;
  
      &lt;variable name=&quot;aHomeViewModel&quot;
          type=&quot;info.dodata.voicerecorder.viewcontrol.HomeViewModel&quot; /&gt;
  &lt;/data&gt;
  
  &lt;LinearLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;?android:attr/listPreferredItemHeight&quot;
      android:orientation=&quot;horizontal&quot;&gt;
  
      &lt;TextView
         android:id=&quot;@+id/voiceID&quot;
         android:layout_width=&quot;wrap_content&quot;
         android:layout_height=&quot;wrap_content&quot;
         android:text=&quot;@{Integer.toString(aMVoice.id)}&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/title_text&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginLeft=&quot;50dp&quot;
          android:text=&quot;@{aMVoice.name}&quot; /&gt;
      ...
  &lt;/LinearLayout&gt;
  
  &lt;/layout&gt;
  </code></pre>
  <p><strong>Added Content</strong></p>
  <p>If I use Code A, I will get the new compile warning information Warning A.</p>
  <p><strong>Code A</strong></p>
  <pre><code>binding.btnDelete.setOnClickListener {
      binding.aHomeViewModel!!.delete(binding.amVoice!!)
  }
  </code></pre>
  <p><strong>Warning A</strong></p>
  <p>Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
  Use '--warning-mode all' to show the individual deprecation warnings.</p>