# Class MapField&lt;K,V&gt; (3.19.4)

    public class MapField<K,V> implements MutabilityOracle

Internal representation of map fields in generated messages.

This class supports accessing the map field as a [Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html) to be used in generated API and
also supports accessing the field as a [List](https://docs.oracle.com/javase/8/docs/api/java/util/List.html) to be used in reflection API. It keeps track
of where the data is currently stored and do necessary conversions between map and list.

This class is a protobuf implementation detail. Users shouldn't use this class directly.

THREAD-SAFETY NOTE: Read-only access is thread-safe. Users can call getMap() and getList()
concurrently in multiple threads. If write-access is needed, all access must be synchronized.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> MapField\<K,V\>

## Implements

com.google.protobuf.MutabilityOracle

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

| ## Type Parameters ||
|---|---|
| **Name** | **Description** |
| `K` |   |
| `V` |   |

## Static Methods

### \<K,V\>emptyMapField(MapEntry\<K,V\> defaultEntry)

    public static MapField<K,V> <K,V>emptyMapField(MapEntry<K,V> defaultEntry)

Returns an immutable empty MapField.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `defaultEntry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MapEntry<K,V>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MapField<K,V>` |   |

### \<K,V\>newMapField(MapEntry\<K,V\> defaultEntry)

    public static MapField<K,V> <K,V>newMapField(MapEntry<K,V> defaultEntry)

Creates a new mutable empty MapField.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `defaultEntry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MapEntry<K,V>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MapField<K,V>` |   |

## Methods

### clear()

    public void clear()

### copy()

    public MapField<K,V> copy()

Returns a deep copy of this MapField.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MapField<K,V>` |   |

### ensureMutable()

    public void ensureMutable()

Throws an UnsupportedOperationException if not mutable.

### equals(Object object)

    public boolean equals(Object object)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `object` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### getMap()

    public Map<K,V> getMap()

Returns the content of this MapField as a read-only Map.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<K,V>` |   |

### getMutableMap()

    public Map<K,V> getMutableMap()

Gets a mutable Map view of this MapField.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<K,V>` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### isMutable()

    public boolean isMutable()

Returns whether this field can be modified.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### makeImmutable()

    public void makeImmutable()

Makes this list immutable. All subsequent modifications will throw an UnsupportedOperationException.

### mergeFrom(MapField\<K,V\> other)

    public void mergeFrom(MapField<K,V> other)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `other` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MapField<K,V>` |