October 2018
Intermediate to advanced
370 pages
9h 15m
English
The this keyword is used to refer to the object that we are currently talking about. In our current Person example, the this keyword refers to the Person object. Take a Person class example and append the this keyword with each property:
class Person(pName: String, pAge: Int, pHeight : Double ) { var name : String var age : Int var height : Double init { this.name = pName this.age = pAge this.height = pHeight } }
The this keyword refers to the name, age, and height properties of the current object. The this keyword is optional and the main reason to use it is to remove the ambiguity between the class property and the local parameter.
Create a simple form of the Person class with one property name and pass a constructor ...
Read now
Unlock full access