----- Mail original ----- > De: "Alan Snyder" <[email protected]> > À: "Remi Forax" <[email protected]> > Cc: "core-libs-dev" <[email protected]> > Envoyé: Vendredi 21 Décembre 2018 03:20:46 > Objet: Re: enhanced for loop with multiple iteration variables
> Lambdas are clean, but limited in current Java compared to nested blocks. > > Are full featured lambdas on the horizon? not in the immediate future, co-routine, sealed class, record, pattern matching, value type and reified generics are the next features. > > If not, then we still need loops and iterators. > > Alan Rémi > > > > >> On Dec 20, 2018, at 3:00 PM, Remi Forax <[email protected]> wrote: >> >> or >> map.forEach((key, value) -> { >> ... >> }); >> >> Rémi >> >> ----- Mail original ----- >>> De: "Brian Goetz" <[email protected]> >>> À: "Alan Snyder" <[email protected]>, "core-libs-dev" >>> <[email protected]> >>> Envoyé: Jeudi 20 Décembre 2018 23:50:15 >>> Objet: Re: enhanced for loop with multiple iteration variables >> >>> For Map, you can do: >>> >>> for (Map.Entry<K,V> e : map.entrySet()) { ... } >>> >>> and you're already there. >>> >>> >>> >>> On 12/19/2018 9:54 AM, Alan Snyder wrote: >>>> Has any consideration been given to supporting iterators that provide more >>>> than >>>> one iteration variable in the enhanced for loop? >>>> >>>> Obvious uses would be maps (keys and values) and lists (indexes and >>>> values). >>>> >>>> I have in mind keeping the syntactic sugar approach by using one or more >>>> extensions of the Iterator/Iterable interfaces, such as, for example: >>>> >>>> interface Iterator2<E1,E2> extends Iterator<E1> { >>>> E2 get2(); >>>> } >>>> >>>> with the extra methods providing the values for the extra variables >>>> (associated >>>> with the previous call to next). >>>> >>>> Extending interfaces is not required, but it makes the trailing variables >>>> optional, which might be useful. For example, the same iterator could >>>> provide >>>> values or values and keys. >>>> >>>> The fact that this approach only works for a fixed set of numbers of >>>> variables >>>> does not bother me unduly. >>>> >>>> Alan
