Hi I was trying to understand the flow in below co...
# getting-started
s
Hi I was trying to understand the flow in below code:
Copy code
1 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 🙂
c
in a
class
,
this
refers to the instance of the class
h
https://pl.kotl.in/gLxVWuNfk From the IDs you can tell the different instances apart.