diesieben07
05/25/2017, 1:26 PMPerson as this in scopealexfu
05/25/2017, 1:30 PMwith(john) { state.isSingle } basically does the same thing as john.state.isSingle right? with takes an object and a block and then executes that block with the object as the argumentdiesieben07
05/25/2017, 1:31 PMjohn as this.alexfu
05/25/2017, 1:32 PMthis in my example refers to State, not Person. or does it not?diesieben07
05/25/2017, 1:33 PMthis. You can access the "`Person` `this`" inside the extension property with this@Person.alexfu
05/25/2017, 1:37 PMdiesieben07
05/25/2017, 1:38 PMPerson instance.alexfu
05/25/2017, 1:45 PMperson.state person is an instance and so is state. so why is the extension property unavailable from that?diesieben07
05/25/2017, 1:48 PMperson is the Person instance to use for the extension property. Say you have a val person and a val person2. Then you do val state = person.state. If you now call state.isSingle the compiler has no way of knowing which Person to use, and making it guess is a terrible idea. You have to be explicit about it.alexfu
05/25/2017, 1:53 PMcompanion object, wouldn’t that effectively be the same as declaring it outside of the class? (i.e. statically and therefore doesn’t require an instance of person)diesieben07
05/25/2017, 1:55 PMthis, which is the companion object instance. So you would need with (MyClass.Companion) { /* call extension property */ }diesieben07
05/25/2017, 1:55 PMalexfu
05/25/2017, 1:59 PMPerson class, it basically can be considered as an instance variable of the Person class?diesieben07
05/25/2017, 2:02 PMumar
05/25/2017, 4:16 PM