Java Variant

In Java, Variant is a class that is defined in two different packages.

  • javax.ws.rs.core.Variant
  • org.eclipse.swt.ole.win32.Variant

javax.ws.rs.core.Variant

It is in-built in JDK. The Java Variant class belongs to javax.ws.rs.core.Variant. It extends the Object class. the class is used for abstraction for a resource representation variant that contains information about media type, language and encoding of the resource representation.

Constructors of the Variant Class

ConstructorDescription
Variant(MediaType mediaType, Locale language, String encoding)Create a new instance of Variant.
Variant(MediaType mediaType, String language, String encoding)
Variant(MediaType m diaType, String language, String country, String encoding)
Variant(MediaType mediaType, String language, String country, String languageVariant, String encoding)

Methods of the Variant Class

The class provides the following methods:

MethodDescription
encodings(String... encodings)It creates a Variant.VariantListBuilder initialized with a set of supported encodings.
equals(Object obj)It compares obj to this variant to see if they are the same considering all property values.
getEncoding()The method gets the encoding of the variant.
getLanguage()The method gets the language of the variant.
getLanguageString()The method gets the string representation of the variant language, or null if no language has been set.
getMediaType()The method gets the media type of the variant.
hashCode()The method generates hash code from variant properties.
languages(Locale... languages)It creates a Variant.VariantListBuilder initialized with a set of supported languages.
mediaTypes(MediaType... mediaTypes)It creates a Variant.VariantListBuilder initialized with a set of supported media types.
toString()toString in class Object.

org.eclipse.swt.ole.win32.Variant

It is a third-party library. A Variant is a generic OLE mechanism for passing data of different types via a common interface. It is used within the OleAutomation object for getting a property, setting a property or invoking a method on an OLE Control or OLE Document.

Fields of The Variant Class

Field NameDescription
NULLA shared Variant instance with type VT_NULL.
sizeofThe size in bytes of a native VARIANT struct.

Constructors of The Variant Class

ConstructorDescription
Variant()It creates an empty Variant object with type VT_EMPTY.
Variant(boolean val)It creates a Variant object that represents a Java boolean as a VT_BOOL.
Variant(double val)It creates a Variant object that represents a Java double as a VT_R8.
Variant(float val)It creates a Variant object that represents a Java float as a VT_R4.
Variant(int val)It creates a Variant object that represents a Java int as a VT_I4.
Variant(long val)It creates a Variant object that represents a Java long as a VT_I8.
Variant(long ptr, short byRefType)It creates a Variant object that contains a reference to the data being transferred.
Variant(short val)It creates a Variant object that represents a Java short as a VT_I2.
Variant(String string)It creates a Variant object that represents a Java String as a VT_BSTR.
Variant(org.eclipse.swt.internal.ole.win32.IDispatch idispatch)It creates a Variant object that represents an IDispatch interface as a VT_Dispatch.
Variant(org.eclipse.swt.internal.ole.win32.IUnknown unknown)It creates a Variant object that represents an IUnknown interface as a VT_UNKNOWN.
Variant(OleAutomation automation)It creates a Variant object that represents an IDispatch interface as a VT_Dispatch.

Methods of The Variant Class

MethodDescription
dispose()It releases the resources associated with this Variant.
getAutomation()The method returns the OleAutomation object represented by this Variant.
getBoolean()The method returns the Java boolean represented by this Variant.
getByRef()The method returns a pointer to the referenced data represented by this Variant.
getByte()The method returns the Java byte represented by this Variant.
getChar()The method returns the Java char represented by this Variant.
getDispatch()The method returns the IDispatch object represented by this Variant.
getDouble()The method returns the Java double represented by this Variant.
getFloat()The method returns the Java float represented by this Variant.
getInt()The method returns the Java int represented by this Variant.
getLong()The method returns the Java long represented by this Variant.
getShort()The method returns the Java short represented by this Variant.
getString()The method returns the Java String represented by this Variant.
getType()The method returns the type of the variant type.
getUnknown()The method returns the IUnknown object represented by this Variant.
setByRef(boolean val)The method updates the by reference value of this variant with a new boolean value.
setByRef(float val)The method updates the by reference value of this variant with a new float value.
setByRef(long val)The method updates the by reference value of this variant with a new integer value.
setByRef(short val)The method updates the by reference value of this variant with a new short value.
toString()The method returns a string containing a concise, human-readable description of the receiver.
win32_copy(long pVarDest, Variant varSrc)It invokes platform specific functionality to copy a variant into operating system memory.
win32_new(long pVariant)It invokes platform specific functionality to wrap a variant that was allocated in operating system memory.





Latest Courses