[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: RFR: 8304947: Unnecessary Vector usage in java.awt.MenuBar.shortcuts
From:       Andrey Turbanov <aturbanov () openjdk ! org>
Date:       2023-03-28 19:53:46
Message-ID: Athnipwa1AwjL8uuLAn2O73EwhgwyfF4m5d1Dm-A0-w=.f2c53ba6-66d9-4e91-afc4-580ca24acf51 () github ! com
[Download RAW message or body]

On Fri, 24 Mar 2023 07:21:27 GMT, Sergey Bylokhov <serb@openjdk.org> wrote:

> > Behavior is the same.
> > `Enumeration` doesn't have `remove` method. Only `hasMoreElements` and \
> > `nextElement`. Method creates a new collection for result each time, hence no \
> > updates of underlying collection are possible. Iteration order is the same too.
> > 
> > Vector<String> v = new Vector<>();
> > v.add("123");
> > v.add("444");
> > v.add("555");
> > v.add("666");
> > 
> > Enumeration<String> elements = v.elements();
> > while (elements.hasMoreElements()) {
> > String s = elements.nextElement();
> > System.out.println(s);
> > }
> > System.out.println();
> > 
> > ArrayList<String> a = new ArrayList<>(v);
> > Enumeration<String> e = Collections.enumeration(a);
> > while (e.hasMoreElements()) {
> > String s = e.nextElement();
> > System.out.println(s);
> > }
> > 
> > gives
> > 
> > 123
> > 444
> > 555
> > 666
> > 
> > 123
> > 444
> > 555
> > 666
> 
> but there is an asIterator method that may support remove

`Vector.elements()` and `Collections.enumeration(ArrayList)` returns `Enumeration` \
implementations that don't override `asIterator` method. Default implementation \
`java.util.Enumeration#asIterator` doesn't support remove too. So, we are safe here.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13149#discussion_r1147979096


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic