jaroslav@559: /* jaroslav@559: * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. jaroslav@559: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@559: * jaroslav@559: * This code is free software; you can redistribute it and/or modify it jaroslav@559: * under the terms of the GNU General Public License version 2 only, as jaroslav@559: * published by the Free Software Foundation. Oracle designates this jaroslav@559: * particular file as subject to the "Classpath" exception as provided jaroslav@559: * by Oracle in the LICENSE file that accompanied this code. jaroslav@559: * jaroslav@559: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@559: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@559: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@559: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@559: * accompanied this code). jaroslav@559: * jaroslav@559: * You should have received a copy of the GNU General Public License version jaroslav@559: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@559: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@559: * jaroslav@559: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@559: * or visit www.oracle.com if you need additional information or have any jaroslav@559: * questions. jaroslav@559: */ jaroslav@559: jaroslav@559: package java.lang; jaroslav@559: jaroslav@559: import java.lang.annotation.*; jaroslav@559: jaroslav@559: /** jaroslav@559: * A programmer assertion that the body of the annotated method or jaroslav@559: * constructor does not perform potentially unsafe operations on its jaroslav@559: * varargs parameter. Applying this annotation to a method or jaroslav@559: * constructor suppresses unchecked warnings about a jaroslav@559: * non-reifiable variable arity (vararg) type and suppresses jaroslav@559: * unchecked warnings about parameterized array creation at call jaroslav@559: * sites. jaroslav@559: * jaroslav@559: *
In addition to the usage restrictions imposed by its {@link jaroslav@559: * Target @Target} meta-annotation, compilers are required to implement jaroslav@559: * additional usage restrictions on this annotation type; it is a jaroslav@559: * compile-time error if a method or constructor declaration is jaroslav@559: * annotated with a {@code @SafeVarargs} annotation, and either: jaroslav@559: *
Compilers are encouraged to issue warnings when this annotation jaroslav@559: * type is applied to a method or constructor declaration where: jaroslav@559: * jaroslav@559: *
jaroslav@559: * jaroslav@559: * leads to a {@code ClassCastException} at runtime. jaroslav@559: * jaroslav@559: *jaroslav@559: * @SafeVarargs // Not actually safe! jaroslav@559: * static void m(List<String>... stringLists) { jaroslav@559: * Object[] array = stringLists; jaroslav@559: * List<Integer> tmpList = Arrays.asList(42); jaroslav@559: * array[0] = tmpList; // Semantically invalid, but compiles without warnings jaroslav@559: * String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime! jaroslav@559: * } jaroslav@559: *
Future versions of the platform may mandate compiler errors for jaroslav@559: * such unsafe operations. jaroslav@559: * jaroslav@559: *