Kotlin Properties

In Kotlin, you can access properties of objects directly, using the object.property syntax, without the need for an access method (getters and setters in Java). You can see this in action in many places throughout the ContactsActivity class:

  • In the setupRecyclerView() method, the recyclerView.setAdapter(mAdapter) method is replaced with recyclerView.adapter = mAdapter and viewHolder.getPosition() with viewHolder.position.
  • The EditText setText() and, getText() methods are replaced throughout with the text property. The setEnabled() method is replaced with the isEnabled property.
  • The size of the mContacts list is accessed with mContacts.size throughout.
  • You can access one of the items in the mContacts list using mContacts[index] instead of mContacts.get(index).

results matching ""

    No results matching ""