what is the difference between these two code ? `...
# android
a
what is the difference between these two code ?
Copy code
class VerifyAppIntegrityUseCase(
    val authRepository: AuthRepository,
    val workbenchUserRepository: WorkbenchUserRepository,
    val menuRepository: MenuRepository,
    val subscriptionRepository: SubscriptionRepository,
    val adkarRepository: AdkarRepository,
    val securedKeyValueStoreRepository: SecuredKeyValueStoreRepository,
 >>>   dispatcher: CoroutineDispatcher
) :
    AuthenticatedFlowUseCase<Unit, Unit>(authRepository, dispatcher), UseCaseScope
Copy code
class VerifyAppIntegrityUseCase(
    val authRepository: AuthRepository,
    val workbenchUserRepository: WorkbenchUserRepository,
    val menuRepository: MenuRepository,
    val subscriptionRepository: SubscriptionRepository,
    val adkarRepository: AdkarRepository,
    val securedKeyValueStoreRepository: SecuredKeyValueStoreRepository,
>>> val dispatcher: CoroutineDispatcher
) :
    AuthenticatedFlowUseCase<Unit, Unit>(authRepository, dispatcher), UseCaseScope
why would kotlin give such a dual option here, both options allow us to pass it to the Super class constructor
p
Well if you have it as a val, you can also use it inside the class and access it from the outside
👀 1
c
The difference here is how this Kotlin code compiles to Java. In the case of specifying
val
on the constructor property, you are defining this as a global variable in the class, which is instantiated in the constructor. In the case of not specifying
val
the property is not a global variable, but is just a constructor scoped property that can only be used when the instance of the class is being generated via the constructor.
🙌 3