Class MediaType
-
- com.google.common.net.MediaType
-
@Beta @GwtCompatible public final class MediaType extends
Represents an (also known as a MIME Type or Content Type). This class also supports the concept of media ranges . As such, the*
character is treated as a wildcard and is used to represent any acceptable type or subtype value. A media type may not have wildcard type with a declared subtype. The*
character has no special meaning as part of a parameter. All values for type, subtype, parameter attributes or parameter values must be valid according to RFCs and .All portions of the media type that are case-insensitive (type, subtype, parameter attributes) are normalized to lowercase. The value of the
charset
parameter is normalized to lowercase, but all others are left as-is.Note that this specifically does not represent the value of the MIME
Content-Type
header and as such has no support for header-specific considerations such as line folding and comments.For media types that take a charset the predefined constants default to UTF-8 and have a "_UTF_8" suffix. To get a version without a character set, use
withoutParameters()
.- Since:
- 12.0
- Author:
- Gregory Kick
-
-
Field Summary
Fields Modifier and Type Field Description static MediaType
AAC_AUDIO
Advanced Audio Coding.static MediaType
ANY_APPLICATION_TYPE
static MediaType
ANY_AUDIO_TYPE
static MediaType
ANY_FONT_TYPE
Wildcard matching any "font" top-level media type.static MediaType
ANY_IMAGE_TYPE
static MediaType
ANY_TEXT_TYPE
static MediaType
ANY_TYPE
static MediaType
ANY_VIDEO_TYPE
static MediaType
APPLE_MOBILE_CONFIG
.static MediaType
APPLE_PASSBOOK
.static MediaType
APPLICATION_BINARY
This is a non-standard media type, but is commonly used in serving hosted binary files as it is .static MediaType
APPLICATION_XML_UTF_8
As described in , this constant (application/xml
) is used for XML documents that are "unreadable by casual users."XML_UTF_8
is provided for documents that may be read by users.static MediaType
ATOM_UTF_8
static MediaType
BASIC_AUDIO
Basic Audio, as defined by .static MediaType
BMP
(bmp
files).static MediaType
BZIP2
static MediaType
CACHE_MANIFEST_UTF_8
static MediaType
CRW
The (crw
files), a widely-used "raw image" format for cameras.static MediaType
CSS_UTF_8
static MediaType
CSV_UTF_8
static MediaType
DART_UTF_8
Files in the programming language.static MediaType
EOT
fonts.static MediaType
EPUB
As described in the EPUB is the distribution and interchange format standard for digital publications and documents.static MediaType
FLV_VIDEO
Flash video.static MediaType
FONT_COLLECTION
A collection of font outlines as defined by .static MediaType
FONT_OTF
(OTF) as defined by .static MediaType
FONT_SFNT
(SFNT).static MediaType
FONT_TTF
(TTF) as defined by .static MediaType
FONT_WOFF
(WOFF).static MediaType
FONT_WOFF2
(WOFF2).static MediaType
FORM_DATA
static MediaType
GEO_JSON
Media type for the , a geospatial data interchange format based on JSON.static MediaType
GIF
static MediaType
GZIP
static MediaType
HAL_JSON
.static MediaType
HEIF
.static MediaType
HTML_UTF_8
static MediaType
I_CALENDAR_UTF_8
static MediaType
ICO
static MediaType
JAVASCRIPT_UTF_8
declares this to be the correct media type for JavaScript, buttext/javascript
may be necessary in certain situations for compatibility.static MediaType
JOSE
For .static MediaType
JOSE_JSON
For .static MediaType
JP2K
.static MediaType
JPEG
static MediaType
JSON_UTF_8
static MediaType
KEY_ARCHIVE
As described in , PKCS #12 defines an archive file format for storing many cryptography objects as a single file.static MediaType
KML
.static MediaType
KMZ
, compressed using the ZIP format into KMZ archives.static MediaType
L16_AUDIO
L16 audio, as defined by .static MediaType
L24_AUDIO
L24 audio, as defined by .static MediaType
MANIFEST_JSON_UTF_8
The .static MediaType
MBOX
The .static MediaType
MEDIA_PRESENTATION_DESCRIPTION
Media type for .static MediaType
MICROSOFT_EXCEL
spreadsheets.static MediaType
MICROSOFT_OUTLOOK
items.static MediaType
MICROSOFT_POWERPOINT
presentations.static MediaType
MICROSOFT_WORD
documents.static MediaType
MP4_AUDIO
static MediaType
MP4_VIDEO
static MediaType
MPEG_AUDIO
static MediaType
MPEG_VIDEO
static MediaType
NACL_APPLICATION
NaCl applications.static MediaType
NACL_PORTABLE_APPLICATION
NaCl portable applications.static MediaType
OCTET_STREAM
static MediaType
OGG_AUDIO
static MediaType
OGG_CONTAINER
static MediaType
OGG_VIDEO
static MediaType
OOXML_DOCUMENT
static MediaType
OOXML_PRESENTATION
static MediaType
OOXML_SHEET
static MediaType
OPENDOCUMENT_GRAPHICS
static MediaType
OPENDOCUMENT_PRESENTATION
static MediaType
OPENDOCUMENT_SPREADSHEET
static MediaType
OPENDOCUMENT_TEXT
static MediaType
OPENSEARCH_DESCRIPTION_UTF_8
Description files are XML files that describe how a website can be used as a search engine by consumers (e.g.static MediaType
PDF
static MediaType
PLAIN_TEXT_UTF_8
static MediaType
PNG
static MediaType
POSTSCRIPT
static MediaType
PROTOBUF
static MediaType
PSD
The Photoshop File Format (psd
files) as defined by , and found in/etc/mime.types
, e.g.static MediaType
QUICKTIME
static MediaType
RDF_XML_UTF_8
documents, which are XML serializations of graphs.static MediaType
RTF_UTF_8
static MediaType
SFNT
declaresfont/sfnt
to be the correct media type for SFNT, but this may be necessary in certain situations for compatibility.static MediaType
SHOCKWAVE_FLASH
static MediaType
SKETCHUP
skp
files produced by the 3D Modeling softwarestatic MediaType
SOAP_XML_UTF_8
As described in , this constant (application/soap+xml
) is used to identify SOAP 1.2 message envelopes that have been serialized with XML 1.0.static MediaType
SVG_UTF_8
static MediaType
TAR
static MediaType
TEXT_JAVASCRIPT_UTF_8
declaresapplication/javascript
to be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.static MediaType
THREE_GPP_VIDEO
The 3GP multimedia container format.static MediaType
THREE_GPP2_VIDEO
The 3G2 multimedia container format.static MediaType
TIFF
static MediaType
TSV_UTF_8
.static MediaType
VCARD_UTF_8
static MediaType
VND_REAL_AUDIO
Real Audio.static MediaType
VND_WAVE_AUDIO
WAVE format, as defined by .static MediaType
VORBIS_AUDIO
Vorbis Audio, as defined by .static MediaType
VTT_UTF_8
As described in , this is used for Web Video Text Tracks (WebVTT) files, used with the HTML5 track element.static MediaType
WASM_APPLICATION
WASM applications.static MediaType
WAX_AUDIO
Windows Media metafiles.static MediaType
WEBM_AUDIO
static MediaType
WEBM_VIDEO
static MediaType
WEBP
.static MediaType
WMA_AUDIO
Windows Media Audio.static MediaType
WML_UTF_8
UTF-8 encoded .static MediaType
WMV
static MediaType
WOFF
declaresfont/woff
to be the correct media type for WOFF, but this may be necessary in certain situations for compatibility.static MediaType
WOFF2
declaresfont/woff2
to be the correct media type for WOFF2, but this may be necessary in certain situations for compatibility.static MediaType
XHTML_UTF_8
static MediaType
XML_UTF_8
As described in , this constant (text/xml
) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8
is provided for documents that are intended for applications.static MediaType
XRD_UTF_8
Extensible Resource Descriptors.static MediaType
ZIP
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description >
charset()
Returns an optional charset for the value of the charset parameter if it is specified.static MediaType
type, subtype)
Creates a new media type with the given type and subtype.boolean
obj)
Indicates whether some other object is "equal to" this one.int
hashCode()
Returns a hash code value for the object.boolean
hasWildcard()
Returns true if either the type or subtype is the wildcard.boolean
is(MediaType mediaTypeRange)
Returnstrue
if this instance falls within the range (as defined by ) given by the argument according to three criteria: The type of the argument is the wildcard or equal to the type of this instance.,>
parameters()
Returns a multimap containing the parameters of this media type.static MediaType
input)
Parses a media type from its string representation.subtype()
Returns the media subtype.toString()
Returns the string representation of this media type in the format described in .type()
Returns the top-level media type.MediaType
charset)
Returns a new instance with the same type and subtype as this instance, with thecharset
parameter set to the of the given charset.MediaType
withoutParameters()
Returns a new instance with the same type and subtype as this instance, but without any parameters.MediaType
attribute, value)
Replaces all parameters with the given attribute with a single parameter with the given value.MediaType
,> parameters)
Replaces all parameters with the given parameters.MediaType
attribute, <> values)
Replaces all parameters with the given attribute with parameters using the given values.
-
-
-
Field Detail
-
ANY_TEXT_TYPE
public static final MediaType ANY_TEXT_TYPE
-
ANY_IMAGE_TYPE
public static final MediaType ANY_IMAGE_TYPE
-
ANY_AUDIO_TYPE
public static final MediaType ANY_AUDIO_TYPE
-
ANY_VIDEO_TYPE
public static final MediaType ANY_VIDEO_TYPE
-
ANY_APPLICATION_TYPE
public static final MediaType ANY_APPLICATION_TYPE
-
ANY_FONT_TYPE
public static final MediaType ANY_FONT_TYPE
Wildcard matching any "font" top-level media type.- Since:
- 30.0
-
CACHE_MANIFEST_UTF_8
public static final MediaType CACHE_MANIFEST_UTF_8
-
HTML_UTF_8
public static final MediaType HTML_UTF_8
-
I_CALENDAR_UTF_8
public static final MediaType I_CALENDAR_UTF_8
-
PLAIN_TEXT_UTF_8
public static final MediaType PLAIN_TEXT_UTF_8
-
TEXT_JAVASCRIPT_UTF_8
public static final MediaType TEXT_JAVASCRIPT_UTF_8
declaresapplication/javascript
to be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.
-
VCARD_UTF_8
public static final MediaType VCARD_UTF_8
-
XML_UTF_8
public static final MediaType XML_UTF_8
As described in , this constant (text/xml
) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8
is provided for documents that are intended for applications.
-
VTT_UTF_8
public static final MediaType VTT_UTF_8
As described in , this is used for Web Video Text Tracks (WebVTT) files, used with the HTML5 track element.- Since:
- 20.0
-
CRW
public static final MediaType CRW
The (crw
files), a widely-used "raw image" format for cameras. It is found in/etc/mime.types
, e.g. in .- Since:
- 15.0
-
PSD
public static final MediaType PSD
The Photoshop File Format (psd
files) as defined by , and found in/etc/mime.types
, e.g. of the Apache ; for the specification, see and ; this is the regular output/input of Photoshop (which can also export to various image formats; note that files with extension "PSB" are in a distinct but related format).This is a more recent replacement for the older, experimental type
x-photoshop
: .- Since:
- 15.0
-
MPEG_AUDIO
public static final MediaType MPEG_AUDIO
-
WEBM_AUDIO
public static final MediaType WEBM_AUDIO
-
BASIC_AUDIO
public static final MediaType BASIC_AUDIO
Basic Audio, as defined by .- Since:
- 20.0
-
AAC_AUDIO
public static final MediaType AAC_AUDIO
Advanced Audio Coding. For more information, see .- Since:
- 20.0
-
VORBIS_AUDIO
public static final MediaType VORBIS_AUDIO
Vorbis Audio, as defined by .- Since:
- 20.0
-
WMA_AUDIO
public static final MediaType WMA_AUDIO
Windows Media Audio. For more information, see .- Since:
- 20.0
-
WAX_AUDIO
public static final MediaType WAX_AUDIO
Windows Media metafiles. For more information, see .- Since:
- 20.0
-
VND_REAL_AUDIO
public static final MediaType VND_REAL_AUDIO
Real Audio. For more information, see .- Since:
- 20.0
-
VND_WAVE_AUDIO
public static final MediaType VND_WAVE_AUDIO
WAVE format, as defined by .- Since:
- 20.0
-
MPEG_VIDEO
public static final MediaType MPEG_VIDEO
-
WEBM_VIDEO
public static final MediaType WEBM_VIDEO
-
FLV_VIDEO
public static final MediaType FLV_VIDEO
Flash video. For more information, see .- Since:
- 20.0
-
THREE_GPP_VIDEO
public static final MediaType THREE_GPP_VIDEO
The 3GP multimedia container format. For more information, see 3GPP TS 26.244.- Since:
- 20.0
-
THREE_GPP2_VIDEO
public static final MediaType THREE_GPP2_VIDEO
The 3G2 multimedia container format. For more information, see .- Since:
- 20.0
-
APPLICATION_XML_UTF_8
public static final MediaType APPLICATION_XML_UTF_8
As described in , this constant (application/xml
) is used for XML documents that are "unreadable by casual users."XML_UTF_8
is provided for documents that may be read by users.- Since:
- 14.0
-
ATOM_UTF_8
public static final MediaType ATOM_UTF_8
-
DART_UTF_8
public static final MediaType DART_UTF_8
Files in the programming language.- Since:
- 19.0
-
APPLE_PASSBOOK
public static final MediaType APPLE_PASSBOOK
.- Since:
- 19.0
-
EPUB
public static final MediaType EPUB
As described in the EPUB is the distribution and interchange format standard for digital publications and documents. This media type is defined in the specification.- Since:
- 15.0
-
KEY_ARCHIVE
public static final MediaType KEY_ARCHIVE
As described in , PKCS #12 defines an archive file format for storing many cryptography objects as a single file.- Since:
- 15.0
-
APPLICATION_BINARY
public static final MediaType APPLICATION_BINARY
This is a non-standard media type, but is commonly used in serving hosted binary files as it is . It should not be used in other situations as it is not specified by any RFC and does not appear in the list. ConsiderOCTET_STREAM
for binary data that is not being served to a browser.- Since:
- 14.0
-
GEO_JSON
public static final MediaType GEO_JSON
Media type for the , a geospatial data interchange format based on JSON.- Since:
- 28.0
-
JAVASCRIPT_UTF_8
public static final MediaType JAVASCRIPT_UTF_8
declares this to be the correct media type for JavaScript, buttext/javascript
may be necessary in certain situations for compatibility.
-
JSON_UTF_8
public static final MediaType JSON_UTF_8
-
MANIFEST_JSON_UTF_8
public static final MediaType MANIFEST_JSON_UTF_8
The .- Since:
- 19.0
-
APPLE_MOBILE_CONFIG
public static final MediaType APPLE_MOBILE_CONFIG
.- Since:
- 18.0
-
MICROSOFT_EXCEL
public static final MediaType MICROSOFT_EXCEL
spreadsheets.
-
MICROSOFT_OUTLOOK
public static final MediaType MICROSOFT_OUTLOOK
items.- Since:
- 27.1
-
MICROSOFT_POWERPOINT
public static final MediaType MICROSOFT_POWERPOINT
presentations.
-
MICROSOFT_WORD
public static final MediaType MICROSOFT_WORD
documents.
-
MEDIA_PRESENTATION_DESCRIPTION
public static final MediaType MEDIA_PRESENTATION_DESCRIPTION
Media type for . This is with the IANA.- Since:
- 28.2
-
WASM_APPLICATION
public static final MediaType WASM_APPLICATION
WASM applications. For more information see .- Since:
- 27.0
-
NACL_APPLICATION
public static final MediaType NACL_APPLICATION
NaCl applications. For more information see .- Since:
- 20.0
-
NACL_PORTABLE_APPLICATION
public static final MediaType NACL_PORTABLE_APPLICATION
NaCl portable applications. For more information see .- Since:
- 20.0
-
OCTET_STREAM
public static final MediaType OCTET_STREAM
-
OGG_CONTAINER
public static final MediaType OGG_CONTAINER
-
OOXML_DOCUMENT
public static final MediaType OOXML_DOCUMENT
-
OOXML_PRESENTATION
public static final MediaType OOXML_PRESENTATION
-
OOXML_SHEET
public static final MediaType OOXML_SHEET
-
OPENDOCUMENT_GRAPHICS
public static final MediaType OPENDOCUMENT_GRAPHICS
-
OPENDOCUMENT_PRESENTATION
public static final MediaType OPENDOCUMENT_PRESENTATION
-
OPENDOCUMENT_SPREADSHEET
public static final MediaType OPENDOCUMENT_SPREADSHEET
-
OPENDOCUMENT_TEXT
public static final MediaType OPENDOCUMENT_TEXT
-
OPENSEARCH_DESCRIPTION_UTF_8
public static final MediaType OPENSEARCH_DESCRIPTION_UTF_8
Description files are XML files that describe how a website can be used as a search engine by consumers (e.g. web browsers).- Since:
- 28.2
-
POSTSCRIPT
public static final MediaType POSTSCRIPT
-
RDF_XML_UTF_8
public static final MediaType RDF_XML_UTF_8
documents, which are XML serializations of graphs.- Since:
- 14.0
-
SFNT
public static final MediaType SFNT
declaresfont/sfnt
to be the correct media type for SFNT, but this may be necessary in certain situations for compatibility.- Since:
- 17.0
-
SHOCKWAVE_FLASH
public static final MediaType SHOCKWAVE_FLASH
-
SKETCHUP
public static final MediaType SKETCHUP
skp
files produced by the 3D Modeling software- Since:
- 13.0
-
SOAP_XML_UTF_8
public static final MediaType SOAP_XML_UTF_8
As described in , this constant (application/soap+xml
) is used to identify SOAP 1.2 message envelopes that have been serialized with XML 1.0.For SOAP 1.1 messages, see
XML_UTF_8
per- Since:
- 20.0
-
WOFF
public static final MediaType WOFF
declaresfont/woff
to be the correct media type for WOFF, but this may be necessary in certain situations for compatibility.- Since:
- 17.0
-
WOFF2
public static final MediaType WOFF2
declaresfont/woff2
to be the correct media type for WOFF2, but this may be necessary in certain situations for compatibility.- Since:
- 20.0
-
XHTML_UTF_8
public static final MediaType XHTML_UTF_8
-
XRD_UTF_8
public static final MediaType XRD_UTF_8
Extensible Resource Descriptors. This is not yet registered with the IANA, but it is specified by OASIS in the and implemented in projects such as .- Since:
- 14.0
-
FONT_COLLECTION
public static final MediaType FONT_COLLECTION
A collection of font outlines as defined by .- Since:
- 30.0
-
FONT_SFNT
public static final MediaType FONT_SFNT
(SFNT). declares this to be the correct media type for SFNT, butapplication/font-sfnt
may be necessary in certain situations for compatibility.- Since:
- 30.0
-
FONT_WOFF
public static final MediaType FONT_WOFF
(WOFF). declares this to be the correct media type for SFNT, butapplication/font-woff
may be necessary in certain situations for compatibility.- Since:
- 30.0
-
FONT_WOFF2
public static final MediaType FONT_WOFF2
(WOFF2). declares this to be the correct media type for SFNT, butapplication/font-woff2
may be necessary in certain situations for compatibility.- Since:
- 30.0
-
-
Method Detail
-
type
public type()
Returns the top-level media type. For example,"text"
in"text/plain"
.
-
subtype
public subtype()
Returns the media subtype. For example,"plain"
in"text/plain"
.
-
parameters
public ,> parameters()
Returns a multimap containing the parameters of this media type.
-
charset
public > charset()
Returns an optional charset for the value of the charset parameter if it is specified.- Throws:
- if multiple charset values have been set for this media type
- if a charset value is present, but illegal
- if a charset value is present, but no support is available in this instance of the Java virtual machine
-
withoutParameters
public MediaType withoutParameters()
Returns a new instance with the same type and subtype as this instance, but without any parameters.
-
withParameters
public ,> parameters)
Replaces all parameters with the given parameters.- Throws:
- if any parameter or value is invalid
-
withParameters
public attribute, <> values)
Replaces all parameters with the given attribute with parameters using the given values. If there are no values, any existing parameters with the given attribute are removed.- Throws:
- if either
attribute
orvalues
is invalid- Since:
- 24.0
-
withParameter
public attribute, value)
Replaces all parameters with the given attribute with a single parameter with the given value. If multiple parameters with the same attributes are necessary usewithParameters(String, Iterable)
. PreferwithCharset(java.nio.charset.Charset)
for setting thecharset
parameter when using a object.- Throws:
- if either
attribute
orvalue
is invalid
-
withCharset
public charset)
Returns a new instance with the same type and subtype as this instance, with thecharset
parameter set to the of the given charset. Only onecharset
parameter will be present on the new instance regardless of the number set on this one.If a charset must be specified that is not supported on this JVM (and thus is not representable as a instance, use
withParameter(java.lang.String, java.lang.String)
.
-
hasWildcard
public boolean hasWildcard()
Returns true if either the type or subtype is the wildcard.
-
is
public boolean is(MediaType mediaTypeRange)
Returnstrue
if this instance falls within the range (as defined by ) given by the argument according to three criteria:- The type of the argument is the wildcard or equal to the type of this instance.
- The subtype of the argument is the wildcard or equal to the subtype of this instance.
- All of the parameters present in the argument are present in this instance.
For example:
PLAIN_TEXT_UTF_8.is(PLAIN_TEXT_UTF_8) // true PLAIN_TEXT_UTF_8.is(HTML_UTF_8) // false PLAIN_TEXT_UTF_8.is(ANY_TYPE) // true PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE) // true PLAIN_TEXT_UTF_8.is(ANY_IMAGE_TYPE) // false PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE.withCharset(UTF_8)) // true PLAIN_TEXT_UTF_8.withoutParameters().is(ANY_TEXT_TYPE.withCharset(UTF_8)) // false PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE.withCharset(UTF_16)) // false
Note that while it is possible to have the same parameter declared multiple times within a media type this method does not consider the number of occurrences of a parameter. For example,
"text/plain; charset=UTF-8"
satisfies"text/plain; charset=UTF-8; charset=UTF-8"
.
-
create
public static type, subtype)
Creates a new media type with the given type and subtype.- Throws:
- if type or subtype is invalid or if a wildcard is used for the type, but not the subtype.
-
parse
public static input)
Parses a media type from its string representation.- Throws:
- if the input is not parsable
-
equals
public boolean obj)
Description copied from class:Indicates whether some other object is "equal to" this one.The
equals
method implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
The
equals
method for classObject
implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesx
andy
, this method returnstrue
if and only ifx
andy
refer to the same object (x == y
has the valuetrue
).Note that it is generally necessary to override the
hashCode
method whenever this method is overridden, so as to maintain the general contract for thehashCode
method, which states that equal objects must have equal hash codes.- Overrides:
in class
- Parameters:
obj
- the reference object with which to compare.- Returns:
true
if this object is the same as the obj argument;false
otherwise.- See Also:
- ,
- It is reflexive: for any non-null reference value
-
hashCode
public int hashCode()
Description copied from class:Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by .The general contract of
hashCode
is:- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCode
method must consistently return the same integer, provided no information used inequals
comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)
method, then calling thehashCode
method on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
method, then calling the
hashCode
method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class
Object
does return distinct integers for distinct objects. (The hashCode may or may not be implemented as some function of an object's memory address at some point in time.)- Overrides:
in class
- Returns:
- a hash code value for this object.
- See Also:
- ,
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
-
toString
public toString()
Returns the string representation of this media type in the format described in .- Overrides:
in class
- Returns:
- a string representation of the object.
-
-