diff --git a/src/java.base/share/classes/java/util/Arrays.java b/src/java.base/share/classes/java/util/Arrays.java index 4947b2bbf54..f92cfd4fb68 100644 --- a/src/java.base/share/classes/java/util/Arrays.java +++ b/src/java.base/share/classes/java/util/Arrays.java @@ -25,7 +25,6 @@ package java.util; -import jdk.internal.misc.Unsafe; import jdk.internal.util.ArraysSupport; import jdk.internal.vm.annotation.IntrinsicCandidate; @@ -2507,7 +2506,7 @@ public class Arrays { * @param a2 the other array to be tested for equality * @return {@code true} if the two arrays are equal */ - public static boolean equals(short[] a, short a2[]) { + public static boolean equals(short[] a, short[] a2) { if (a==a2) return true; if (a==null || a2==null) diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 5d50b0d6e4e..808094e4116 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -141,7 +141,6 @@ public class Collections { * found to violate the {@link Comparable} contract * @see List#sort(Comparator) */ - @SuppressWarnings("unchecked") public static > void sort(List list) { list.sort(null); } @@ -175,7 +174,6 @@ public class Collections { * found to violate the {@link Comparator} contract * @see List#sort(Comparator) */ - @SuppressWarnings({"unchecked", "rawtypes"}) public static void sort(List list, Comparator c) { list.sort(c); } @@ -267,7 +265,7 @@ public class Collections { * list listIterator. */ private static T get(ListIterator i, int index) { - T obj = null; + T obj; int pos = i.nextIndex(); if (pos <= index) { do { @@ -651,10 +649,10 @@ public class Collections { * @throws NoSuchElementException if the collection is empty. * @see Comparable */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked"}) public static T min(Collection coll, Comparator comp) { if (comp==null) - return (T)min((Collection) coll); + return (T)min((Collection>) coll); Iterator i = coll.iterator(); T candidate = i.next(); @@ -724,10 +722,10 @@ public class Collections { * @throws NoSuchElementException if the collection is empty. * @see Comparable */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked"}) public static T max(Collection coll, Comparator comp) { if (comp==null) - return (T)max((Collection) coll); + return (T)max((Collection>) coll); Iterator i = coll.iterator(); T candidate = i.next(); @@ -1067,7 +1065,7 @@ public class Collections { public String toString() {return c.toString();} public Iterator iterator() { - return new Iterator() { + return new Iterator<>() { private final Iterator i = c.iterator(); public boolean hasNext() {return i.hasNext();} @@ -1279,7 +1277,6 @@ public class Collections { private Object readResolve() { return EMPTY_NAVIGABLE_SET; } } - @SuppressWarnings("rawtypes") private static final NavigableSet EMPTY_NAVIGABLE_SET = new EmptyNavigableSet<>(); @@ -1392,7 +1389,7 @@ public class Collections { public ListIterator listIterator() {return listIterator(0);} public ListIterator listIterator(final int index) { - return new ListIterator() { + return new ListIterator<>() { private final ListIterator i = list.listIterator(index); @@ -1634,10 +1631,9 @@ public class Collections { @java.io.Serial private static final long serialVersionUID = 7854390611657943733L; - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"unchecked"}) UnmodifiableEntrySet(Set> s) { - // Need to cast to raw in order to work around a limitation in the type system - super((Set)s); + super((Set>)s); } static Consumer> entryConsumer( @@ -1721,7 +1717,7 @@ public class Collections { } public Iterator> iterator() { - return new Iterator>() { + return new Iterator<>() { private final Iterator> i = c.iterator(); public boolean hasNext() { @@ -1920,7 +1916,7 @@ public class Collections { private static final long serialVersionUID = -4858195264774772197L; /** - * A class for the {@link EMPTY_NAVIGABLE_MAP} which needs readResolve + * A class for the {@link #EMPTY_NAVIGABLE_MAP} which needs readResolve * to preserve singleton property. * * @param type of keys, if there were any, and of bounds @@ -1943,7 +1939,7 @@ public class Collections { } /** - * Singleton for {@link emptyNavigableMap()} which is also immutable. + * Singleton for {@link #emptyNavigableMap()} which is also immutable. */ private static final EmptyNavigableMap EMPTY_NAVIGABLE_MAP = new EmptyNavigableMap<>(); @@ -3191,7 +3187,7 @@ public class Collections { // JDK-6363904 - unwrapped iterator could be typecast to // ListIterator with unsafe set() final Iterator it = c.iterator(); - return new Iterator() { + return new Iterator<>() { public boolean hasNext() { return it.hasNext(); } public E next() { return it.next(); } public void remove() { it.remove(); } @@ -3582,7 +3578,7 @@ public class Collections { public ListIterator listIterator(final int index) { final ListIterator i = list.listIterator(index); - return new ListIterator() { + return new ListIterator<>() { public boolean hasNext() { return i.hasNext(); } public E next() { return i.next(); } public boolean hasPrevious() { return i.hasPrevious(); } @@ -3890,7 +3886,7 @@ public class Collections { public Iterator> iterator() { final Iterator> i = s.iterator(); - return new Iterator>() { + return new Iterator<>() { public boolean hasNext() { return i.hasNext(); } public void remove() { i.remove(); } @@ -4745,7 +4741,6 @@ public class Collections { // Override default methods in Map @Override - @SuppressWarnings("unchecked") public V getOrDefault(Object k, V defaultValue) { return defaultValue; } @@ -4826,7 +4821,7 @@ public class Collections { } static Iterator singletonIterator(final E e) { - return new Iterator() { + return new Iterator<>() { private boolean hasNext = true; public boolean hasNext() { return hasNext; @@ -4859,7 +4854,7 @@ public class Collections { * @return A singleton {@code Spliterator} */ static Spliterator singletonSpliterator(final T element) { - return new Spliterator() { + return new Spliterator<>() { long est = 1; @Override @@ -5061,7 +5056,7 @@ public class Collections { public Set> entrySet() { if (entrySet==null) - entrySet = Collections.>singleton( + entrySet = Collections.singleton( new SimpleImmutableEntry<>(k, v)); return entrySet; } @@ -5429,8 +5424,8 @@ public class Collections { public boolean equals(Object o) { return (o == this) || - (o instanceof ReverseComparator2 && - cmp.equals(((ReverseComparator2)o).cmp)); + (o instanceof ReverseComparator2 that && + cmp.equals(that.cmp)); } public int hashCode() { @@ -5459,7 +5454,7 @@ public class Collections { * @see Enumeration */ public static Enumeration enumeration(final Collection c) { - return new Enumeration() { + return new Enumeration<>() { private final Iterator i = c.iterator(); public boolean hasMoreElements() {