Fri, 24 Apr 2020 03:58:51 +0100
Merge
sadayapalam@2812 | 1 | /* |
sadayapalam@2812 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
sadayapalam@2812 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sadayapalam@2812 | 4 | * |
sadayapalam@2812 | 5 | * This code is free software; you can redistribute it and/or modify it |
sadayapalam@2812 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sadayapalam@2812 | 7 | * published by the Free Software Foundation. |
sadayapalam@2812 | 8 | * |
sadayapalam@2812 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sadayapalam@2812 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sadayapalam@2812 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sadayapalam@2812 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sadayapalam@2812 | 13 | * accompanied this code). |
sadayapalam@2812 | 14 | * |
sadayapalam@2812 | 15 | * You should have received a copy of the GNU General Public License version |
sadayapalam@2812 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sadayapalam@2812 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sadayapalam@2812 | 18 | * |
sadayapalam@2812 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sadayapalam@2812 | 20 | * or visit www.oracle.com if you need additional information or have any |
sadayapalam@2812 | 21 | * questions. |
sadayapalam@2812 | 22 | */ |
sadayapalam@2812 | 23 | |
sadayapalam@2812 | 24 | /* |
sadayapalam@2812 | 25 | * @test |
sadayapalam@2812 | 26 | * @bug 8080842 |
sadayapalam@2812 | 27 | * @summary Ensure Scope impl can cope with remove() when a field and method share the name. |
sadayapalam@2812 | 28 | * @run main RemoveSymbolTest |
sadayapalam@2812 | 29 | */ |
sadayapalam@2812 | 30 | |
sadayapalam@2812 | 31 | import java.util.Iterator; |
sadayapalam@2812 | 32 | import java.util.LinkedList; |
sadayapalam@2812 | 33 | |
sadayapalam@2812 | 34 | public class RemoveSymbolTest<W> implements Iterable<W> { |
sadayapalam@2812 | 35 | static class Widget { |
sadayapalam@2812 | 36 | private String name; |
sadayapalam@2812 | 37 | Widget(String s) { name = s; } |
sadayapalam@2812 | 38 | @Override public String toString() { return name; } |
sadayapalam@2812 | 39 | } |
sadayapalam@2812 | 40 | |
sadayapalam@2812 | 41 | private LinkedList<W> data; |
sadayapalam@2812 | 42 | // Instantiate an Iterable instance using a Lambda expression. |
sadayapalam@2812 | 43 | // Causes ClassFormatError if a local variable of type Widget is named after one of the methods. |
sadayapalam@2812 | 44 | private final Iterable<W> myIterator1 = () -> new Iterator<W>() { |
sadayapalam@2812 | 45 | private W hasNext = null; |
sadayapalam@2812 | 46 | private int index = 0; |
sadayapalam@2812 | 47 | @Override public boolean hasNext() { return index < data.size(); } |
sadayapalam@2812 | 48 | @Override public W next() { return data.get(index++); } |
sadayapalam@2812 | 49 | }; |
sadayapalam@2812 | 50 | |
sadayapalam@2812 | 51 | // Instantiate an Iterable instance using an anonymous class. |
sadayapalam@2812 | 52 | // Always works fine regardless of the name of the local variable. |
sadayapalam@2812 | 53 | private final Iterable<W> myIterator2 = |
sadayapalam@2812 | 54 | new Iterable<W>() { |
sadayapalam@2812 | 55 | @Override |
sadayapalam@2812 | 56 | public Iterator<W> iterator() { |
sadayapalam@2812 | 57 | return new Iterator<W>() { |
sadayapalam@2812 | 58 | private W hasNext = null; |
sadayapalam@2812 | 59 | private int index = 0; |
sadayapalam@2812 | 60 | @Override public boolean hasNext() { return index < data.size(); } |
sadayapalam@2812 | 61 | @Override public W next() { return data.get(index++); } |
sadayapalam@2812 | 62 | }; |
sadayapalam@2812 | 63 | } |
sadayapalam@2812 | 64 | }; |
sadayapalam@2812 | 65 | public RemoveSymbolTest() { data = new LinkedList<>(); } |
sadayapalam@2812 | 66 | public void add(W e) { data.add(e); } |
sadayapalam@2812 | 67 | @Override public String toString() { return data.toString(); } |
sadayapalam@2812 | 68 | @Override public Iterator<W> iterator() { return myIterator1.iterator(); } |
sadayapalam@2812 | 69 | public static void main(String[] args) { |
sadayapalam@2812 | 70 | RemoveSymbolTest<Widget> widgets = new RemoveSymbolTest<>(); |
sadayapalam@2812 | 71 | widgets.add(new Widget("W1")); |
sadayapalam@2812 | 72 | widgets.add(new Widget("W2")); |
sadayapalam@2812 | 73 | widgets.add(new Widget("W3")); |
sadayapalam@2812 | 74 | System.out.println(".foreach() call: "); |
sadayapalam@2812 | 75 | widgets.forEach(w -> System.out.println(w + " ")); |
sadayapalam@2812 | 76 | } |
sadayapalam@2812 | 77 | } |