共用方式為


ISafeVarargs Interface

Definition

A programmer assertion that the body of the annotated method or constructor does not perform potentially unsafe operations on its varargs parameter.

[Android.Runtime.Register("java/lang/SafeVarargs", "", "Java.Lang.ISafeVarargsInvoker")]
public interface ISafeVarargs : IDisposable, Java.Interop.IJavaPeerable, Java.Lang.Annotation.IAnnotation
[<Android.Runtime.Register("java/lang/SafeVarargs", "", "Java.Lang.ISafeVarargsInvoker")>]
type ISafeVarargs = interface
    interface IAnnotation
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Attributes
Implements

Remarks

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 @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: <ul> <li> the declaration is a fixed arity method or constructor

<li> the declaration is a variable arity method that is neither static nor final nor private.

</ul>

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

<ul>

<li> 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.)

<li> 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

<blockquote>

&#64;SafeVarargs // Not actually safe!
            static void m(List&lt;String&gt;... stringLists) {
              Object[] array = stringLists;
              List&lt;Integer&gt; tmpList = Arrays.asList(42);
              array[0] = tmpList; // Semantically invalid, but compiles without warnings
              String s = stringLists[0].get(0); // Oh no, ClassCastException at runtime!
            }

</blockquote>

leads to a ClassCastException at runtime.

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

</ul>

Added in 1.7.

Java documentation for java.lang.SafeVarargs.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

AnnotationType()

Returns the annotation interface of this annotation.

(Inherited from IAnnotation)
Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Equals(Object)

Returns true if the specified object represents an annotation that is logically equivalent to this one.

(Inherited from IAnnotation)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
GetHashCode()

Returns the hash code of this annotation.

(Inherited from IAnnotation)
SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
ToString()

Returns a string representation of this annotation.

(Inherited from IAnnotation)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to