title: Kotlin generic classes
body: <p>I am new to Kotlin and am trying to access a specific field within a generic class</p>
  
  <p>I have tried all sorts of potential solutions - The problem that I have is that I don't know how to inform Kotlin that the field name in the class that I pass across exists.</p>
  
  <p>This is my class :-</p>
  
  <pre><code>@Entity(tableName = "coursemark_table")
  @Parcelize
  class CourseMark(
      @field:PrimaryKey
      @field:ColumnInfo(name = "coursemark_number")
      var number: Int,
      var name: String,
      var latitude: String,
      var longitude: String,
      var passTo: String
  ): Parcelable
  </code></pre>
  
  <p>This is the generic list adapter class that I am trying to initialise - I can't work out how to get at the name field in CourseMark in the OnBindViewHolder function I can understand why since BaseListHolder has no knowledge of the field names in CourseMark until it is initialised but there must be a way of telling the Kotlin compiler that this field exists - My apologies for posting this but I have been struggling for a number of days to figure this out :-</p>
  
  <pre><code>abstract class BaseListAdapter&lt;T&gt; internal constructor(context: Context) :
      RecyclerView.Adapter&lt;BaseListAdapter&lt;T&gt;.BaseViewHolder&gt;() {
  
      private val mInflater: LayoutInflater = LayoutInflater.from(context)
      private var mMarks = emptyList&lt;T&gt;() // Cached copy of marks
  
      inner class BaseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
          val markItemView: TextView = itemView.findViewById(R.id.textView)
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
          val itemView = mInflater.inflate(R.layout.recyclerview_coursemark, parent, false)
          return BaseViewHolder(itemView)
      }
  
      override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
          val current = mMarks[position]
          holder.markItemView.text = current.name
      }
  
      /**
       * Associate a list of marks with this adapter
       */
  
      internal fun setMarks(marks: List&lt;T&gt;) {
          mMarks = marks
          notifyDataSetChanged()
      }
  
      // getItemCount() is called many times, and when it is first called,
      // mMarks has not been updated (means initially, it's null, and we can't return null).
      override fun getItemCount(): Int {
          return mMarks.size
      }
  
      /**
       * Get the mark at a given position.
       * This method is useful for identifying which mark
       * was clicked or swiped in methods that handle user events.
       *
       * @param position
       * @return The mark at the given position
       */
      fun getMarkAtPosition(position: Int): T {
          return mMarks[position]
      }
  
  }
  </code></pre>