Perhaps I’m mistaken or uninformed, but it does lo...
# android
j
Perhaps I’m mistaken or uninformed, but it does look like there are times when the Kotlin property syntax is misleading: e.g. I’m writing some code to cancel jobs via JobScheduler, and so in Kotlin I have the following code:
Copy code
val jobScheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as android.app.job.JobScheduler
jobScheduler.allPendingJobs
where
jobScheduler.allPendingJobs
is property syntax for the abstract method
JobScheduler#getAllPendingJobs
Initially I figured I’m just accessing a member variable of the
JobScheduler
(apparently abstract) class but when I dive into
JobScheduler
, I noticed that
allPendingJobs
is actually an abstract method, which, for all I know, is doing some intensive work and has not already done that work I guess what I’m asking is, why does Kotlin and/or the IDE use property syntax on abstract methods? or am I misunderstanding what “property syntax” means? or…? Thanks for your time!
hmmm, maybe this is actually more related to the Jetbrains IDE than to Kotlin - but even if that’s the case, then why is the IDE providing property syntax to an abstract method?
l
You should just use WorkManager instead of tricky JobScheduler (that will be deprecated)
1
j
that was just my example of what I experienced to be misleading
g
How abstract method syntax for Java getters is different from the same case with non abstract methods? Kotlin plugin by default uses property syntax for Java getters, just because it shorter and less noisy, overall I don't see any difference on usage of getAllPebdingJobs() and allPendingJobs in this case (except first is longer) This may concidered as violation of style guide about Property vs Function, but it mostly applied to Kotlin code, where developer decide, but in this case it is just convenient syntax, if you think that would be better to use getter instead, just use it (what you cannot do with Kotlin property)