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, therecyclerView.setAdapter(mAdapter)
method is replaced withrecyclerView.adapter = mAdapter
andviewHolder.getPosition()
withviewHolder.position
. - The EditText
setText()
and,getText()
methods are replaced throughout with the text property. ThesetEnabled()
method is replaced with theisEnabled
property. - The size of the
mContacts
list is accessed withmContacts.size
throughout. - You can access one of the items in the
mContacts
list usingmContacts[index]
instead ofmContacts.get(index)
.