Class Variant
public final class Variant
{
// Fields
public static final short VariantArray;
public static final short VariantBoolean;
public static final short VariantByref;
public static final short VariantByte;
public static final short VariantCurrency;
public static final short VariantDate;
public static final short VariantDispatch;
public static final short VariantDouble;
public static final short VariantEmpty;
public static final short VariantError;
public static final short VariantFloat;
public static final short VariantInt;
public static final short VariantNull;
public static final short VariantObject;
public static final short VariantShort;
public static final short VariantString;
public static final short VariantTypeMask;
public static final short VariantVariant;
// Constructors
public Variant();
public Variant(int val);
public Variant(double val);
public Variant(boolean val);
public Variant(String val);
public Variant(SafeArray val, boolean fByRef);
public Variant(Object value);
public Variant(int vartype, int val);
public Variant(int vartype, boolean val);
public Variant(int vartype, double val);
public Variant(int vartype, Object val);
public Variant(Object value, boolean unwrapScriptObjects);
// Methods
public native void changeType (short vartype);
public void changeType (int vartype);
public Object clone ();
public Variant cloneIndirect ();
protected void finalize();
public native boolean getBoolean ();
public native boolean getBooleanRef ();
public byte getByte ();
public native byte getByteRef ();
public long getCurrency ();
public native long getCurrencyRef();
public double getDate ();
public native double getDateRef ();
public native Object getDispatch ();
public native Object getDispatchRef();
public double getDouble ();
public native double getDoubleRef ();
public void getEmpty ();
public int getError ();
public native int getErrorRef ();
public float getFloat ();
public native float getFloatRef ();
public int getInt ();
public native int getIntRef ();
public void getNull ();
public native Object getObject ();
public native Object getObjectRef ();
public short getShort ();
public native short getShortRef ();
public native String getString ();
public native String getStringRef ();
public native Variant[] getVariantArray();
public native Variant[] getVariantArrayRef();
public short getvt ();
public void noParam ();
public void putBoolean (boolean val);
public native void putBooleanRef(boolean val);
public void putByte (byte val);
public native void putByteArray(Object ba);
public native void putByteRef (byte val);
public native void putCharArray(Object ca);
public void putCurrency (long val);
public native void putCurrencyRef(long val);
public void putDate (double val);
public native void putDateRef (double val);
public native void putDispatch (Object val);
public native void putDispatchRef(Object val);
public void putDouble (double val);
public native void putDoubleRef(double val);
public void putEmpty ( );
public void putError (int val);
public native void putErrorRef (int val);
public void putFloat (float val);
public native void putFloatRef (float val);
public void putInt (int val);
public native void putIntRef (int val);
public void putNull ( );
public native void putObject (Object val);
public native void putObjectRef(Object val);
public void putSafeArray(SafeArray sa);
public void putSafeArrayRef(SafeArray sa);
public void putShort (short val);
public native void putShortRef (short val);
public native void putString (String val);
public native void putStringRef(String val);
public native void putVariantArray(Variant v[]);
public native void putVariantArrayRef(Variant v[]);
public native boolean toBoolean () throws ClassCastException;
public native byte toByte () throws ClassCastException;
public native Object toByteArray();
public native Object toCharArray();
public native long toCurrency () throws ClassCastException;
public native double toDate () throws ClassCastException;
public native Object toDispatch () throws ClassCastException;
public native double toDouble () throws ClassCastException;
public native int toError () throws ClassCastException;
public native float toFloat () throws ClassCastException;
public native int toInt () throws ClassCastException;
public native Object toObject () throws ClassCastException;
public SafeArray toSafeArray() throws ClassCastException;
public native Object toScriptObject () throws ClassCastException;
public native short toShort () throws ClassCastException;
public String toString ();
public native Variant[] toVariantArray();
public void VariantClear();
}
This class is used to bridge Java with Microsoft® ActiveX® components that manipulate VARIANT data types.
Most Variant methods fall into one of three categories:
- toXXX methods, which attempt to coerce the Variant object to type XXX and return the converted value. The results of the coercion are not copied back to the Variant object. Coercion is performed by using the Microsoft® Win32® VariantChangeType function. If the Variant object cannot be converted to the requested type, a ClassCastException is thrown.
- getXXX methods, which succeed only if the Variant object is already the correct type. If not, a ClassCastException is thrown.
- putXXX methods, which change the type of a Variant object and initialize it to a new value. In general, it is better to construct and initialize the Variant object atomically by using an overloaded constructor rather than to use one of these methods.
public Variant();
Creates a Variant object of type VT_EMPTY.
public Variant(int val);
Creates a Variant object of type VT_I4.
Parameter | Description |
val
| The initial value of the Variant object.
|
public Variant(double val);
Creates a Variant object of type VT_R8.
Parameter | Description |
val
| The initial value of the Variant object.
|
public Variant(boolean val);
Creates a Variant object of type VT_BOOL.
Parameter | Description |
val
| The initial value of the Variant object.
|
public Variant(String val);
Creates a Variant object of type VT_BSTR.
Parameter | Description |
val
| The initial value of the Variant object.
|
public Variant(SafeArray val, boolean fByRef);
Creates a Variant object of type VT_ARRAY or VT_BYREF|VT_ARRAY.
Typically, fByRef is set to true when you create a Variant object to pass as a parameter, and it is false when you create a Variant object that is used as a return value.
Parameter | Description |
val
| The initial SafeArray value.
|
fByRef
| Indicates how to set the VT_BYREF modifier.
|
Remarks:
If fByRef is true, any changes made to the SAFEARRAY data structure through the new Variant object will be visible to the SafeArray instance used to initialize the Variant object.
If fByRef is false, the method revokes the SafeArray instance's ownership. Any further operations on that instance will throw an exception. This is because ownership of the SAFEARRAY data structure has been transferred to the new Variant object. To retrieve any changes made through the Variant object, you must call the toSafeArray method to obtain a new proxy.
public Variant(Object value);
Creates a Variant object of type VT_DISPATCH or VT_BYREF|VT_ARRAY.
If the argument is a Java SafeArray object, this constructor is equivalent to the following code.
Variant(value, true)
Otherwise, this constructor creates a VT_DISPATCH.
Parameter | Description |
value
| The initial value.
|
public Variant(int vartype, int val);
Creates a Variant object of the type indicated by vartype. The type can be VariantShort, VariantInt, or VariantByte. The VariantByref modifier can be set on any of these types.
Parameter | Description |
vartype
| The variant type.
|
val
| The initial value.
|
public Variant(int vartype, boolean val);
Creates a Variant object of the type indicated by vartype. The type can be VariantBoolean, or VariantByref|VariantBoolean.
Parameter | Description |
vartype
| The variant type.
|
val
| The initial value.
|
public Variant(int vartype, double val);
Creates a Variant object of the type indicated by vartype. The type can be VariantDouble, VariantFloat, or VariantDate. The VariantByref modifier can be set on any of these types.
Parameter | Description |
vartype
| The variant type.
|
val
| The initial value.
|
public Variant(int vartype, Object val);
Creates a Variant object of the type indicated by vartype. The type can be VariantString, VariantObject, or VariantDispatch. The VariantByref modifier can be set on any of these types.
Parameter | Description |
vartype
| The variant type.
|
val
| The initial value.
|
public Variant(Object value, boolean unwrapScriptObjects);
If unwrapScriptObjects is set to true, this constructor creates an object of the type indicated by value, which may be types VT_BOOL, VT_BSTR, or VT_R8. Otherwise, this constructor creates a VT_DISPATCH.
Parameter | Description |
value
| The initial value.
|
unwrapScriptObjects
| Indicates whether script objects are to be unwrapped.
|
public native void changeType (short vartype);
Invokes the Win32 VariantChangeType function.
Return Value:
No return value.
public void changeType (int vartype);
Invokes the Win32 VariantChangeType function.
Return Value:
No return value.
public Object clone ();
Invokes the Win32 VariantCopy function.
Return Value:
Returns the cloned Variant object.
public Variant cloneIndirect ();
Invokes the Win32 VariantCopyInd function.
Return Value:
Returns the cloned Variant object.
protected void finalize();
Performs cleanup before garbage collection.
Return Value:
No return value.
public native boolean getBoolean ();
Retrieves the value of a VT_BOOL Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java boolean.
Exceptions:
ClassCastException
if the variant type is not VT_BOOL.
public native boolean getBooleanRef ();
Retrieves the referenced value of a VT_BYREF|VT_BOOL Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java boolean.
Exceptions:
ClassCastException
if the Variant is of any other type.
public byte getByte ();
Retrieves the value of a VT_UI1 Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java byte.
Exceptions:
ClassCastException
if the variant type is not VT_UI1.
public native byte getByteRef ();
Retrieves the referenced value of a VT_BYREF|VT_UI1 Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java byte.
Exceptions:
ClassCastException
if the Variant is of any other type.
public long getCurrency ();
Retrieves the value of a VT_CY Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java long.
Exceptions:
ClassCastException
if the variant type is not VT_CY.
public native long getCurrencyRef();
Retrieves the referenced value of a VT_BYREF|VT_CY Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java long.
Exceptions:
ClassCastException
if the Variant is of any other type.
public double getDate ();
Retrieves the value of a VT_DATE Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java double.
Exceptions:
ClassCastException
if the variant type is not VT_DATE.
public native double getDateRef ();
Retrieves the referenced value of a VT_BYREF|VT_DATE Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java double.
Exceptions:
ClassCastException
if the Variant is of any other type.
public native Object getDispatch ();
Retrieves the value of a VT_DISPATCH Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java object.
Exceptions:
ClassCastException
if the variant type is not VT_DISPATCH.
public native Object getDispatchRef();
Retrieves the referenced value of a VT_BYREF|VT_DISPATCH Variant.
Return Value:
Returns the Variantobject's referenced value, which is converted to a Java object.
Exceptions:
ClassCastException
if the Variant is of any other type.
public double getDouble ();
Retrieves the value of a VT_R8 Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java double.
Exceptions:
ClassCastException
if the variant type is not VT_R8.
public native double getDoubleRef ();
Retrieves the referenced value of a VT_BYREF|VT_R8 Variant object.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java double.
Exceptions:
ClassCastException
if the Variant is of any other type.
public void getEmpty ();
Verifies that the variant type is VT_EMPTY. This method has no other purpose; there is no value associated with a null Variant.
Return Value:
No return value.
Exceptions:
ClassCastException
if the variant type is not VT_EMPTY.
public int getError ();
Retrieves the value of a VT_ERROR Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java integer.
Exceptions:
ClassCastException
if the variant type is not VT_ERROR.
public native int getErrorRef ();
Retrieves the referenced value of a VT_BYREF|VT_ERROR Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java integer.
Exceptions:
ClassCastException
if the Variant is of any other type.
public float getFloat ();
Retrieves the value of a VT_R4 Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java float.
Exceptions:
ClassCastException
if the variant type is not VT_R4.
public native float getFloatRef ();
Retrieves the referenced value of a VT_BYREF|VT_R4 Variant object.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java float.
Exceptions:
ClassCastException
if the Variant is of any other type.
public int getInt ();
Retrieves the value of a VT_I4 Variant.
Return Value:
Returns the Variant object's value converted to a Java integer.
Exceptions:
ClassCastException
if the variant type is not VT_I4.
public native int getIntRef ();
Retrieves the referenced value of a VT_BYREF|VT_I4 Variant object.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java integer.
Exceptions:
ClassCastException
if the Variant is of any other type.
public void getNull ();
Verifies that the variant type is VT_NULL. This method has no other purpose; there is no value associated with a null Variant.
Return Value:
No return value.
Exceptions:
ClassCastException
if the variant type is not VT_NULL.
public native Object getObject ();
Retrieves the value of a VT_UNKNOWN Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java object.
Exceptions:
ClassCastException
if the variant type is not VT_UNKNOWN.
public native Object getObjectRef ();
Retrieves the referenced value of a VT_BYREF|VT_UNKNOWN Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java object.
Exceptions:
ClassCastException
if the Variant is of any other type.
public short getShort ();
Retrieves the value of a VT_I2 Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java short.
Exceptions:
ClassCastException
if the variant type is not VT_I2.
public native short getShortRef ();
Retrieves the referenced value of a VT_BYREF|VT_I2 Variant object.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java short.
Exceptions:
ClassCastException
if the Variant is of any other type.
public native String getString ();
Retrieves the value of a VT_BSTR Variant.
Return Value:
Returns the Variant object's value, which is converted to a Java string.
Exceptions:
ClassCastException
if the variant type is not VT_BSTR.
public native String getStringRef ();
Retrieves the referenced value of a VT_BYREF|VT_BSTR Variant.
Return Value:
Returns the Variant object's referenced value, which is converted to a Java string.
Exceptions:
ClassCastException
if the Variant is of any other type.
public native Variant[] getVariantArray();
Retrieves the value of a VT_ARRAY|VT_VARIANT Variant. The embedded array must be one-dimensional. This is an "expensive" method, which has been superceded by the toSafeArray method.
Return Value:
Returns the Variant's value converted to a Java array of Variants.
public native Variant[] getVariantArrayRef();
Retrieves the referenced value of a VT_BYREF|VT_ARRAY|VT_VARIANT Variant. The embedded array must be one-dimensional. This is an "expensive" method, which has been superceded by the toSafeArray method.
Return Value:
Returns the Variant's referenced value converted to a Java array of Variant objects.
public short getvt ();
Extracts the variant type of the Variant object.
Return Value:
Returns the variant type.
public void noParam ();
Sets a Variant object to represent a missing optional parameter. This method is equivalent to the expression
putError(0x80020004) //DISP_E_PARAMNOTFOUND
Return Value:
No return value.
public void putBoolean (boolean val);
Sets the Variant object to type VT_BOOL and clears the previous contents.
Note The preferred way to create a VT_BOOL Variant is to use the following expression.
new Variant(val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putBooleanRef(boolean val);
Replaces a value referenced by a VT_BYREF|VT_BOOL Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantBoolean,val).
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putByte (byte val);
Sets the Variant object to be type VT_UI1 and clears the previous contents.
Note The preferred way to create a VT_UI1 Variant is to use the following expression.
new Variant(Variant.VariantByte, val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putByteArray(Object ba);
Sets a Variant object to type VT_ARRAY|VT_UI1 and clears the previous contents.
Return Value:
No return value.
Parameter | Description |
ba
| The initial values of the elements, which must be byte[].
|
public native void putByteRef (byte val);
Replaces a value referenced by a VT_BYREF|VT_UI1 Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantByte,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putCharArray(Object ca);
Sets Variant to type VT_ARRAY|VT_I2 and clears the previous contents.
Return Value:
No return value.
Parameter | Description |
ca
| The initial values of the elements, which must be char[].
|
public void putCurrency (long val);
Sets the Variant object to type VT_CY and clears the previous contents.
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putCurrencyRef(long val);
Replaces a value referenced by a VT_BYREF|VT_CY Variant object.
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putDate (double val);
Sets the Variant object to type VT_DATE and clears the previous contents.
Note The preferred way to create a VT_DATE Variant is to use the following expression.
new Variant(Variant.VariantDate, val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putDateRef (double val);
Replaces a value referenced by a VT_BYREF|VT_DATE Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantDate,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putDispatch (Object val);
Sets the Variant object to type VT_DISPATCH and clears the previous contents.
Note The preferred way to create a VT_DISPATCH Variant is to use the following expression.
new Variant(val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putDispatchRef(Object val);
Replaces a value referenced by a VT_BYREF|VT_DISPATCH Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantDispatch,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putDouble (double val);
Sets the Variant object to type VT_R8 and clears the previous contents.
Note The preferred way to create a VT_R8 Variant is to use the following expression.
new Variant(val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putDoubleRef(double val);
Replaces a value referenced by a VT_BYREF|VT_R8 Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantDouble,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putEmpty ( );
Sets the Variant object to type VT_EMPTY and clears the previous contents. The expression
new Variant()
creates a new Variant object that is already type VT_EMPTY, so it is not necessary to invoke the putEmpty method on such an object.
Return Value:
No return value.
public void putError (int val);
Sets the Variant object to type VT_ERROR and clears the previous contents. This object is normally passed as a placeholder for a missing optional parameter.
Note The preferred way to generate a missing parameter is to use the following code.
Variant v = new Variant(val);
v.noParam();
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putErrorRef (int val);
Replaces a value referenced by a VT_BYREF|VT_ERROR Variant.
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putFloat (float val);
Sets the Variant object to type VT_R4 and clears the previous contents.
Note The preferred way to create a VT_R4 Variant is to use the following expression.
new Variant(Variant.VariantFloat, val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putFloatRef (float val);
Replaces a value referenced by a VT_BYREF|VT_R4 Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantFloat,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putInt (int val);
Sets the Variant object to type VT_I4 and clears the previous contents.
Note The preferred way to create a VT_I4 Variant is to use the following expression.
new Variant(val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putIntRef (int val);
Replaces a value referenced by a VT_BYREF|VT_I4 Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantInt,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putNull ( );
Sets the Variant object to type VT_NULL and clears the previous contents.
Return Value:
No return value.
public native void putObject (Object val);
Sets the Variant object to be type VT_UNKNOWN and clears the previous contents.
Note The preferred way to create a VT_UNKNOWN Variant is to use the following expression.
new Variant(Variant.VariantObject, val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putObjectRef(Object val);
Replaces a value referenced by a VT_BYREF|VT_UNKNOWN Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantObject, val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public void putSafeArray(SafeArray sa);
Sets the Variant object to type SAFEARRAY and clears the previous contents. This method sets the variant type to VT_ARRAY.
Return Value:
No return value.
Parameter | Description |
sa
| The SafeArray object.
|
public void putSafeArrayRef(SafeArray sa);
Replaces a SafeArray object referenced by the Variant. This method sets the variant type to VT_BYREF|VT_ARRAY.
Return Value:
No return value.
public void putShort (short val);
Sets the Variant object to type VT_I2 and clears the previous contents.
Note The preferred way to create a VT_I2 Variant is to use the following expression.
new Variant(Variant.VariantShort, val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putShortRef (short val);
Replaces a value referenced by a VT_BYREF|VT_I2 Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is to use the following expression.
new Variant(Variant.VariantByref|Variant.VariantShort,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putString (String val);
Sets the Variant object to type VT_BSTR and clears the previous contents.
Note The preferred way to create a VT_BSTR Variant is to use the following expression.
new Variant(val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putStringRef(String val);
Replaces a value referenced by a VT_BYREF|VT_BSTR Variant object.
Note This method can also be used to initialize a Variant, but the preferred method is use the following expression.
new Variant(Variant.VariantByref|Variant.VariantString,val)
Return Value:
No return value.
Parameter | Description |
val
| The new value.
|
public native void putVariantArray(Variant v[]);
Sets a Variant object to a typeVT_ARRAY|VT_VARIANT Variant object, which holds a zero-based, one-dimensional SafeArray.
Return Value:
No return value.
Parameter | Description |
v
| Provides initial values for the SAFEARRAY elements.
|
public native void putVariantArrayRef(Variant v[]);
Replaces a SAFEARRAY data structure, which is referenced by a VT_BYREF|VT_ARRAY|VT_VARIANT Variant.
Note This method can also be used to initialize a Variant object, but the preferred method is to pass a SafeArray object to the Variant constructor.
Return Value:
No return value.
Parameter | Description |
v
| Provides initial values for the SAFEARRAY elements.
|
public native boolean toBoolean () throws ClassCastException;
Coerces the Variant object to a VT_BOOL and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java boolean.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native byte toByte () throws ClassCastException;
Coerces the Variant object to a VT_UI1 and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java byte.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native Object toByteArray();
Retrieves the value of a VT_ARRAY|VT_UI1 or VT_BYREF|VT_ARRAY|VT_UI1 as a one-dimensional byte[] array. This method has been superceded by the toSafeArray method.
Return Value:
Returns a byte array.
public native Object toCharArray();
Retrieves the value of a VT_ARRAY|VT_I2 or VT_BYREF|VT_ARRAY|VT_I2 as a one-dimensional char[] array. This method has been superceded by the toSafeArray method.
Return Value:
Returns a character array.
public native long toCurrency () throws ClassCastException;
Coerces the Variant object to a VT_CY and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value converted to a Java long.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native double toDate () throws ClassCastException;
Coerces the Variant object to a VT_DATE and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java double.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native Object toDispatch () throws ClassCastException;
Coerces the Variant object to a VT_DISPATCH and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java object.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native double toDouble () throws ClassCastException;
Coerces the Variant object to a VT_R8 and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value converted to a Java double.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native int toError () throws ClassCastException;
Coerces the Variant object to a VT_ERROR and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java integer.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native float toFloat () throws ClassCastException;
Coerces the Variant object to a VT_R4 and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value converted to a Java float.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native int toInt () throws ClassCastException;
Coerces the Variant object to a VT_I4 and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value converted to a Java integer.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public native Object toObject () throws ClassCastException;
Coerces the Variant object to a VT_UNKNOWN and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java object.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public SafeArray toSafeArray() throws ClassCastException;
Extracts a SafeArray object from a Variant object that has the VT_ARRAY modifier set. This operation does not create an independent SafeArray object, so it can be used to modify the elements of the SafeArray object that is referenced by the Variant.
Return Value:
Returns the coerced value that is converted to a Java SafeArray object.
Exceptions:
ClassCastException
if the object's type cannot be coerced.
public native Object toScriptObject () throws ClassCastException;
Coerces the Variant script object to a VT_UNKNOWN and returns the coerced result, or converts numbers and strings to Java objects. This method maps VT_BSTR, VT_BOOL, and VT_number to the primitive Java string, boolean, and double types. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java script object.
Exceptions:
ClassCastException
if the Variant script object's type cannot be coerced.
public native short toShort () throws ClassCastException;
Coerces the Variant object to a VT_I2 and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value converted to a Java short.
Exceptions:
ClassCastException
if the Variant object's type cannot be coerced.
public String toString ();
Coerces the Variant object to a VT_BSTR and returns the coerced result. The results of the coercion are not stored in the Variant.
Return Value:
Returns the coerced value that is converted to a Java string.
Remarks:
Unlike the other toXXX methods, no exception is thrown if the variant cannot be coerced to a string. Instead, the toString method of the Object class is called. This is because toString is also the method used for diagnostic printing of all Java objects.
public native Variant[] toVariantArray();
Retrieves the value of either a VT_ARRAY|VT_VARIANT or VT_BYREF|VT_ARRAY|VT_VARIANT Variant. The embedded array must be one-dimensional. This is an "expensive" method, which has been superceded by the toSafeArray method.
Return Value:
Returns the coerced value converted to a Java array of Variants.
public void VariantClear();
Forces the Microsoft® Win32® VariantClear function to be called and resets the Variant object to VT_EMPTY.
Return Value:
No return value.
- VariantArray
- Corresponds to the VT_ARRAY modifier.
- VariantBoolean
- Corresponds to the VT_BOOL variant type.
- VariantByref
- Corresponds to the VT_BYREF modifier.
- VariantByte
- Corresponds to the VT_UI1 variant type.
- VariantCurrency
- Corresponds to the VT_CY variant type.
- VariantDate
- Corresponds to the VT_DATE variant type.
- VariantDispatch
- Corresponds to the VT_DISPATCH variant type.
- VariantDouble
- Corresponds to the VT_R8 variant type.
- VariantEmpty
- Corresponds to the VT_EMPTY variant type.
- VariantError
- Corresponds to the VT_ERROR variant type.
- VariantFloat
- Corresponds to the VT_R4 variant type.
- VariantInt
- Corresponds to the VT_I4 variant type.
- VariantNull
- Corresponds to the VT_NULL variant type.
- VariantObject
- Corresponds to the VT_UNKNOWN variant type.
- VariantShort
- Corresponds to the VT_I2 variant type.
- VariantString
- Corresponds to the VT_BSTR variant type.
- VariantTypeMask
- Masks off variant type modifiers.
- VariantVariant
- Corresponds to the VT_VARIANT variant type.