Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this@MainActivity vs MainActivity@this in kotlin

As you may see that

this@MainActivity or MainActivity@this

is valid while starting activity in kotlin. I tried to find out answer but I did not found anything. Can anyone know about exact difference of it and which one valid ? Why it allowed both ?

like image 548
Smeet Avatar asked Dec 17 '22 19:12

Smeet


1 Answers

According to Kotlin's Grammar documentation,

MainActivity@this is just a label for this with the name "MainActivity". You can set whatever label you want.

this@MainActivity is an actual reference of this from MainActivity

Hope I make it clear.

like image 73
Ye Min Htut Avatar answered Dec 21 '22 09:12

Ye Min Htut