Well, are you on OH3? Maybe this has been changed, but in OH2 it’s working and VSCode is not complaining - at least on my end
And it works, because the lambda gets a copy of iFoo and because we are rescheduling it instead of recreating it iFoo + 1 gets preserved until the next run of the Timer.
see Design Pattern: Recursive Timers - #11 by rlkoshak for more information.