Hi I am making a app with Kotlin and I found that I can both use
textView.setText(str)
and
textView.text =
The method setText()
and getText()
are called setters and getters, they are automatically generated in kotlin.
class ClassName{
var name: String= "some_value"
}
You can use the name
property directly with the object of the class or you can also use the auto-generated setter
method.
class Another{
var c = ClassName()
c.name = "value"
c.setName("value")
}
But if a property starts with a val
instead of var
then it is immutable and does not allow a setter
.
In case you want to read further:-
Setters and getters in kotlin