title: Why can a val property be changed in Kotlin?
body: <p>The Code B is a customized RecyclerView apater with radio button. </p>
  
  <p>mCustomAdapter is changed in both fun methodA() and fun methodB() in Code A, so the reference of <code>get () = mCustomAdapter.getSelectedIndex()</code> is changed too, and it means that the val property mySelectedIndex get value from different address.</p>
  
  <p>In my mind, the val property can't be changed,  why doesn't the app cause error?</p>
  
  <p><strong>Code A</strong></p>
  
  <pre><code>private lateinit var mCustomAdapter: CustomAdapter
  
  private val mySelectedIndex get () = mCustomAdapter.getSelectedIndex()
  
  private fun methodA(){
    mCustomAdapter= CustomAdapter(allListA)
    mRecyclerView.adapter= mCustomAdapter
    backup(mySelectedIndex)
  }
  
  
  private fun methodB(){
    mCustomAdapter= CustomAdapter(allListB)
    mRecyclerView.adapter= mCustomAdapter
    restore(mySelectedIndex) 
  }
  </code></pre>
  
  <p><strong>Code B</strong></p>
  
  <pre><code>class CustomAdapter (val backupItemList: List&lt;MSetting&gt;) : RecyclerView.Adapter&lt;CustomAdapter.ViewHolder&gt;() {
  
      val noRecord=-1
      private var mSelectedIndex = noRecord
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomAdapter.ViewHolder {
          val v = LayoutInflater.from(parent.context).inflate(R.layout.item_recyclerview, parent, false)
          return ViewHolder(v)
      }
  
      fun getSelectedIndex():Int{
          return  mSelectedIndex
      }
  
      fun setSelectedIndex(index:Int){
          if (index in 0..(backupItemList.size-1) ){
              mSelectedIndex=index
          }
          notifyDataSetChanged();
      }
  
      override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) {
          holder.bindItems(backupItemList[position])
      }
  
      override fun getItemCount(): Int {
          return backupItemList.size
      }
  
      inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  
          fun bindItems(aMSetting: MSetting) {          
  
              itemView.radioButton.setOnClickListener {
                  mSelectedIndex=adapterPosition
                  notifyDataSetChanged();
              }
  
              if(adapterPosition == 0 &amp;&amp; mSelectedIndex == noRecord) {            
                  itemView.radioButton.isChecked = true
                  mSelectedIndex=adapterPosition
              }
              else {
                  itemView.radioButton.isChecked =(adapterPosition == mSelectedIndex)
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>Modified</strong> </p>
  
  <p>I think the Code DD and Code EE can get the same effect, right?</p>
  
  <p><strong>Code DD</strong></p>
  
  <pre><code>var aImpl = 0
  val a: Int get() = aImpl
  
  fun seta(){
      aImpl=5
  }
  </code></pre>
  
  <p><strong>Code EE</strong></p>
  
  <pre><code>var b:Int=0
  
  fun setb(){
      b=5
  }
  </code></pre>