Android-CleanArchitecture-Kotlin icon indicating copy to clipboard operation
Android-CleanArchitecture-Kotlin copied to clipboard

operator fun vs execute in the UseCase

Open mahmed1987 opened this issue 6 years ago • 1 comments

I was following your tutorial here at https://fernandocejas.com/2018/05/07/architecting-android-reloaded/ and when I downloaded the project that you linked here , my UseCase class doesn't have the execute method , rather it has this an invoke function which appears to be doing more or less the same thing.

But I was just curious ..why so ?

mahmed1987 avatar Jan 24 '19 07:01 mahmed1987

Invoke - it's kotlin operator which you can override;

Normal function call is: awsomeUseCase.invoke(...), but, overriding of invoke function allows you to do the same call like awsomeUseCase(...), w.o. call of invoke function directly.

It's only syntactic sugar.

freaksgit avatar Jan 24 '19 09:01 freaksgit