# ObjectOutputStream.PutField

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# PutField

```
abstract class PutField
```

|---|----------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                             ||
| ↳ | [java.io.ObjectOutputStream.PutField](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#) |

Provide programmatic access to the persistent fields to be written to ObjectOutput.

## Summary

|                                                   Public constructors                                                   ||
|----------------------------------------------------------------------------------------------------------------------|---|
| [PutField](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#PutField())`()` <br /> |

|                                                                                                                                                                                                                                    Public methods                                                                                                                                                                                                                                    ||
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Boolean))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Put the value of the named boolean field into the persistent field. |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Byte))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html)`)` Put the value of the named byte field into the persistent field.             |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Char))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Char](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char/index.html)`)` Put the value of the named char field into the persistent field.             |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Double))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html)`)` Put the value of the named double field into the persistent field.     |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Float))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Put the value of the named float field into the persistent field.         |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Int))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Put the value of the named int field into the persistent field.                 |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Any))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Put the value of the named Object field into the persistent field.             |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Long))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Put the value of the named long field into the persistent field.             |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [put](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#put(kotlin.String,%20kotlin.Short))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `val:` `[Short](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-short/index.html)`)` Put the value of the named short field into the persistent field.         |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [write](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream.PutField#write(java.io.ObjectOutput))`(`out:` `[ObjectOutput](https://developer.android.com/reference/kotlin/java/io/ObjectOutput)!`)` Write the data and fields to the specified ObjectOutput stream, which must be the same stream that produced this`PutField`object.                                     |

## Public constructors

### PutField

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
PutField()
```

## Public methods

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Boolean
): Unit
```

Put the value of the named boolean field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):the value to assign to the field  |

|                                                                                          Exceptions                                                                                           ||
|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`boolean` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Byte
): Unit
```

Put the value of the named byte field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Byte](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte/index.html):the value to assign to the field        |

|                                                                                         Exceptions                                                                                         ||
|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`byte` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Char
): Unit
```

Put the value of the named char field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Char](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char/index.html):the value to assign to the field        |

|                                                                                         Exceptions                                                                                         ||
|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`char` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Double
): Unit
```

Put the value of the named double field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Double](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-double/index.html):the value to assign to the field    |

|                                                                                          Exceptions                                                                                          ||
|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`double` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Float
): Unit
```

Put the value of the named float field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):the value to assign to the field      |

|                                                                                         Exceptions                                                                                          ||
|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`float` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Int
): Unit
```

Put the value of the named int field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the value to assign to the field          |

|                                                                                        Exceptions                                                                                         ||
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`int` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Any!
): Unit
```

Put the value of the named Object field into the persistent field.

|                                                                Parameters                                                                 ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field              |
| `val`  | [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!:the value to assign to the field (which may be`null`) |

|                                                                                              Exceptions                                                                                               ||
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not a reference type |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Long
): Unit
```

Put the value of the named long field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the value to assign to the field        |

|                                                                                         Exceptions                                                                                         ||
|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`long` |

### put

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun put(
    name: String!, 
    val: Short
): Unit
```

Put the value of the named short field into the persistent field.

|                                                          Parameters                                                          ||
|--------|----------------------------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the name of the serializable field |
| `val`  | [Short](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-short/index.html):the value to assign to the field      |

|                                                                                         Exceptions                                                                                          ||
|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | if`name`does not match the name of a serializable field for the class whose fields are being written, or if the type of the named field is not`short` |

### write

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 15](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun write(out: ObjectOutput!): Unit
```

**Deprecated:** *This method does not write the values contained by this`PutField`object in a proper format, and may result in corruption of the serialization stream. The correct way to write`PutField`data is by calling the[java.io.ObjectOutputStream#writeFields()](https://developer.android.com/reference/kotlin/java/io/ObjectOutputStream#writeFields())method.*

Write the data and fields to the specified ObjectOutput stream, which must be the same stream that produced this`PutField`object.

|                                                               Parameters                                                               ||
|-------|---------------------------------------------------------------------------------------------------------------------------------|
| `out` | [ObjectOutput](https://developer.android.com/reference/kotlin/java/io/ObjectOutput)!:the stream to write the data and fields to |

|                                                       Exceptions                                                        ||
|--------------------------------------|-----------------------------------------------------------------------------------|
| `java.io.IOException`                | if I/O errors occur while writing to the underlying stream                        |
| `java.lang.IllegalArgumentException` | if the specified stream is not the same stream that produced this`PutField`object |