https://kotlinlang.org logo
Title
o

Ofir Bar

01/02/2020, 9:39 PM
Hey guys, can some one please tell me what is this “@addOnCompleteListener” returned here? I searched for “kotlin @” and kotlin annotations, but it seems not to be what is in this code. How is it called? (marked in red square). Please ignore the red arrow for now, this is a different question
b

Ben Abramovitch

01/02/2020, 9:43 PM
It's telling it to return to that point in the code, 4 lines up has the addCompletionListener. So it will exit out of the listener
If you have nested things you sometimes need to be specific about which return
v

Vsevolod Kaganovych

01/02/2020, 9:44 PM
To return from addOnCompleteListener lambda, you specify its name explicitly. If you type just
return
, it will return from the
createUser
function.
a

Anastasia Finogenova

01/02/2020, 10:47 PM
o

Ofir Bar

01/02/2020, 10:47 PM
thanks guys @Ben Abramovitch @Vsevolod Kaganovych I still don’t get something. If I remove the @addCompleteListener, I get a compilation error anyway. Why do I need to explicitly mention it then?
a

Anastasia Finogenova

01/02/2020, 10:47 PM
It is called returns at label
🍕 1
🍻 1
o

Ofir Bar

01/02/2020, 10:47 PM
thanks! this is exactly what I looked for @Anastasia Finogenova
s

StavFX

01/03/2020, 12:41 AM
Ofir, this is why the @ is required. If the method you are calling is
inline
, you have the option to either return from the lambda (what you are trying to do), or, like Vsevolod said, return from
f()
. Since the method you are calling is not inlined, you cannot return
f()
from inside the lambda, but you still must declare it properly, so that if
addOnCompleteListener
ever becomes an
inline
method - your implementation won’t break.
o

Ofir Bar

01/03/2020, 12:03 PM
@StavFX Toda gever, I get it now 🙂, shabat shalom!
🇮🇱 1
😎 2