title: Getting error while dealing with getter and setter in kotlin
body: <p>I have define the data class as:</p>
  
  <pre><code>  data class chatModel(var context:Context?) {
  
        var chatManger:ChatManager?=null
              //getter
          get() = chatManger
              //setter
          set(value) {
              /* execute setter logic */
              chatManger = value
          }
  
      }
  </code></pre>
  
  <p>Now how will i access the get() and set() function. 
  In java I do like that: 
  //for getter</p>
  
  <pre><code>new chatModel().getJId()
  </code></pre>
  
  <p>//for setter</p>
  
  <pre><code>new chatModel().setJId("jid")
  </code></pre>
  
  <p><strong>edit:</strong></p>
  
  <p>As the @yole suggested. I am using setter and getter as:</p>
  
  <p>//set the data</p>
  
  <pre><code>var chatDetails:chatModel=chatModel(mApplicationContext)
   chatDetails.chatManger=chatManager
  </code></pre>
  
  <p>But end up getting the  java.lang.StackOverflowError:                                                                               at </p>
  
  <pre><code>com.example.itstym.smackchat.Model.chatModel.setChatManger(chatModel.kt:38)
  </code></pre>
  
  <p>line 38 points to   </p>
  
  <pre><code>chatManger = value
  </code></pre>
  
  <p>this. </p>
  
  <p>@RobCo suggested.</p>
  
  <p>I have change the data class definition as:</p>
  
  <pre><code>data class chatModel(var context: Context?) {
  
  
      var chatManger:ChatManager
  
      get() = field
      set(value) {
          field=value
      }
  }
  </code></pre>
  
  <p>//set the data.</p>
  
  <pre><code>    chatModel(mApplicationContext).chatManger=chatManager
  </code></pre>
  
  <p>//get the data in different activity</p>
  
  <pre><code>chatModel(applicationContext).chatManger
  </code></pre>
  
  <p>but getting error property must be initialized. If I assigned it to null then I am getting null not the set value. </p>