RFR: 8275106: Cleanup Iterator usages in java.desktop

Sergey Bylokhov serb at openjdk.java.net
Tue Oct 12 08:08:01 UTC 2021


On Fri, 8 Oct 2021 19:37:35 GMT, Andrey Turbanov <duke at openjdk.java.net> wrote:

> Cycles with 'Iterator' are error-prone. It's better to use more high-level code, which easier to read.
> We can use enhanced-for or Collection.removeIf

src/java.desktop/share/classes/javax/swing/JDesktopPane.java line 330:

> 328:     public JInternalFrame[] getAllFramesInLayer(int layer) {
> 329:         Collection<JInternalFrame> allFrames = getAllFrames(this);
> 330:         allFrames.removeIf(jInternalFrame -> jInternalFrame.getLayer() != layer);

This line is longer than 80 char, you can rename jInternalFrame to the frame.

src/java.desktop/unix/classes/sun/awt/X11/ListHelper.java line 569:

> 567: 
> 568:     private boolean isItemSelected(int index) {
> 569:         for (Integer val : selected) {

In some other places you did unboxing for the loop var, why not in this place?

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

PR: https://git.openjdk.java.net/jdk/pull/5871



More information about the client-libs-dev mailing list