In Java you can only close over final variables, so you can't close over the loop variable at all. (Unless that changed since last time I used Java, which - granted - was a long time ago.)
Re:Go 1.21
by doctor_eval on Thursday June 22, 2023 @10:50PM
(#36442238)
The problem being fixed doesn’t affect only closures, but the body of the for loop itself. So for example taking the address of the loop variable would unexpectedly return the same value for the duration of the loop.
The only lesson to be learned here is that languages are different. But I think the new Go behaviour is more ergonomic.