JDK-8300691 - final variables in for loop headers should accept updates
Kevin Bourrillion
kevinb9n at gmail.com
Wed Oct 23 23:14:43 UTC 2024
On Wed, Oct 23, 2024 at 3:53 PM Remi Forax <forax at univ-mlv.fr> wrote:
>
> - for(var i : List.of(0, 1, 2, 3)) {
> - for(var i : IntStream.range(0, 4).boxed().toList()) {
> - for(var i : new int[] { 0, 1, 2, 3 }) {
> - for(var i : (Iterable<Integer>) IntStream.range(0, 4)::iterator) {
> // those students have read Effective Java
>
You've really seen students come up with all of these on their own?
I mean, I credit your students for exploring and trying things, but these
cures are all self-evidently worse than the disease. Hopefully the students
are able to see that they're better off reverting to the "dumb" extra
variable in this case. Then they've learned a useful lesson.
To whatever extent users *really are* feeling compelled to go to such
heroics to avoid this temporary variable, it says something about how
viscerally "wrong" the variable feels. Clearly it's producing a "well
this *can't
be right*, I'd better keep looking for another way" intuition in people.
I suppose that does constitute an argument in favor of the proposal, but I
don't know how it should be weighted. But it would not be reasonable to
compare the proposal against the four things above, and award it points for
being better than *those* things, because they are *already* not the right
solutions for the problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241023/97cf920c/attachment.htm>
More information about the amber-dev
mailing list