skwalking
07/21/2021, 9:21 AM1 class Person(val pets: MutableList<Pet> = mutableListOf())
2
3 class Pet {
4 constructor(owner: Person) {
5 owner.pets.add(this) // adds this pet to the list of its owner's pets
6 }
7 }
Can someone please use above code to make an example on printing something.
Since I'm unable to understand the flow of the code I'm also unable to find what "this" in code line no. 5 does.
Thank you 🙂crummy
07/21/2021, 9:54 AMclass
, this
refers to the instance of the classhho
07/21/2021, 9:58 AM