title: Clone a object in kotlin
body: <p>I have migrated my application from Java to Kotlin. In Java, the copying was working just fine. However, when migrated to Kotline it was not working. After that, I came to know about copy method in Kotlin </p>
  
  <p>I have tied <a href="https://stackoverflow.com/questions/49053432/how-to-clone-object-in-kotlin">this</a>, but it seems I am doing something wrong.</p>
  
  <p>Here is my function : </p>
  
  <pre><code>fun updateSwitchState(deviceName: String, switchNumber: Int): AuraSwitch? {
      val singleDevice = Switch()
      for (c in FourNodeDevice) {
          if (deviceName == c.name) {
              val copyDevice : SwitchClone = SwitchClone(c.state, c.name)
              val state = copyDevice.copy(state = copyDevice.state)
              state.updateState(switchNumber)
              singleDevice.state = state.state
              return singleDevice
          }
      }
      return null
  }
  </code></pre>
  
  <p>Whenever I change data in object <code>state</code> in updateState Method the value in object <code>c</code> also gets changed. Any help will be useful</p>