IT. Expert System.

Java Standard Edition (SE)

SafeVarargs


java.lang

Annotation Type SafeVarargs



  • @Documented
     @Retention(value=RUNTIME)
     @Target(value={CONSTRUCTOR,METHOD})
    public @interface SafeVarargs
    A programmer assertion that the body of the annotated method or constructor does not perform potentially unsafe operations on its varargs parameter. Applying this annotation to a method or constructor suppresses unchecked warnings about a non-reifiable variable arity (vararg) type and suppresses unchecked warnings about parameterized array creation at call sites.

    In addition to the usage restrictions imposed by its @Target meta-annotation, compilers are required to implement additional usage restrictions on this annotation type; it is a compile-time error if a method or constructor declaration is annotated with a @SafeVarargs annotation, and either:

    • the declaration is a fixed arity method or constructor
    • the declaration is a variable arity method that is neither static nor final.

    Compilers are encouraged to issue warnings when this annotation type is applied to a method or constructor declaration where:

    • The variable arity parameter has a reifiable element type, which includes primitive types, Object, and String. (The unchecked warnings this annotation type suppresses already do not occur for a reifiable element type.)
    • The body of the method or constructor declaration performs potentially unsafe operations, such as an assignment to an element of the variable arity parameter's array that generates an unchecked warning. Some unsafe operations do not trigger an unchecked warning. For example, the aliasing in
       @SafeVarargs // Not actually safe!
       static void m(List<String>... stringLists) {
         Object[] array = stringLists;
         List<Integer> tmpList = Arrays.asList(42);
         array[0] = tmpList; // Semantically invalid, but compiles without warnings
         String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime!
       }
       
      leads to a ClassCastException at runtime.

      Future versions of the platform may mandate compiler errors for such unsafe operations.

    Since:
    1.7
    See The Java™ Language Specification:
    4.7 Reifiable Types, 8.4.1 Formal Parameters, 9.6.3.7 @SafeVarargs


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 281 / 158810280. Delta: 0.04325 с