diff options
author | Elliott Hughes <enh@google.com> | 2013-05-11 05:59:22 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-05-11 05:59:22 +0000 |
commit | b1635d52c96e2906485bfe4439d402365d5a025b (patch) | |
tree | d95ee40c2e925acfb0891038e7ec365459211768 | |
parent | 30518b16d0c68f346b4b2f6b90808ad6e11626c5 (diff) | |
parent | bce3d7cfe03fcb70bd374ad2e8b16ba64a45e993 (diff) | |
download | libcore-b1635d52c96e2906485bfe4439d402365d5a025b.zip libcore-b1635d52c96e2906485bfe4439d402365d5a025b.tar.gz libcore-b1635d52c96e2906485bfe4439d402365d5a025b.tar.bz2 |
Merge "Add @SafeVarargs."
-rw-r--r-- | luni/src/main/java/java/lang/SafeVarargs.java | 35 | ||||
-rw-r--r-- | luni/src/main/java/java/util/Arrays.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/java/util/Collections.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/java/util/EnumSet.java | 1 |
4 files changed, 38 insertions, 0 deletions
diff --git a/luni/src/main/java/java/lang/SafeVarargs.java b/luni/src/main/java/java/lang/SafeVarargs.java new file mode 100644 index 0000000..52baa4d --- /dev/null +++ b/luni/src/main/java/java/lang/SafeVarargs.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.lang; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Claims to the compiler that the annotation target does nothing potentially unsafe + * to its varargs argument. + * + * @since 1.7 + */ +@Documented +@Retention(value=RetentionPolicy.RUNTIME) +@Target(value={ElementType.CONSTRUCTOR, ElementType.METHOD}) +public @interface SafeVarargs { +} diff --git a/luni/src/main/java/java/util/Arrays.java b/luni/src/main/java/java/util/Arrays.java index c1b2727..2c84795 100644 --- a/luni/src/main/java/java/util/Arrays.java +++ b/luni/src/main/java/java/util/Arrays.java @@ -150,6 +150,7 @@ public class Arrays { * the array. * @return a {@code List} of the elements of the specified array. */ + @SafeVarargs public static <T> List<T> asList(T... array) { return new ArrayList<T>(array); } diff --git a/luni/src/main/java/java/util/Collections.java b/luni/src/main/java/java/util/Collections.java index 491642b..7c5e059 100644 --- a/luni/src/main/java/java/util/Collections.java +++ b/luni/src/main/java/java/util/Collections.java @@ -2584,6 +2584,7 @@ public class Collections { * if at least one of the elements can't be inserted into the * collection. */ + @SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... a) { boolean modified = false; for (int i = 0; i < a.length; i++) { diff --git a/luni/src/main/java/java/util/EnumSet.java b/luni/src/main/java/java/util/EnumSet.java index 20be6f7..0393511 100644 --- a/luni/src/main/java/java/util/EnumSet.java +++ b/luni/src/main/java/java/util/EnumSet.java @@ -259,6 +259,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> * @throws NullPointerException * if any of the specified elements is {@code null}. */ + @SafeVarargs public static <E extends Enum<E>> EnumSet<E> of(E start, E... others) { EnumSet<E> set = of(start); for (E e : others) { |