title: kotlin - remove nullability from class properties
body: <p>I have a class with some nullable properties</p>
  
  <pre><code>data class RequestModel(
      val description: String?
  )
  </code></pre>
  
  <p>and a validation function</p>
  
  <pre><code>fun validate(model: RequestModel): RequestModel{
      if(model.description == null) throw IllegalArgumentException("description must be non null")
      return model
  }
  </code></pre>
  
  <p>After this validation step, I need a way to indicate non-nullability of <code>description</code> property. </p>
  
  <p>One solution is to create a new data class which has non null propertis <code>data class RequestModel(val description: String)</code>.<br/>But I'm looking for a generic way to avoid creating new classes per use case.</p>
  
  <p>Ideal generic solution:</p>
  
  <pre><code>fun validate(model: RequestModel): NoNullableField&lt;RequestModel&gt;
  </code></pre>
  
  <p>How can I remove nullability from properties of a class with nullable properties in a generic way? Is it usefull to use some kind of kotlin compiler contract?<br/></p>