# BidirectionalTypeConverter

Artifact: [androidx.core:core-animation](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/animation/BidirectionalTypeConverter.java+class:androidx.core.animation.BidirectionalTypeConverter) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

*** ** * ** ***


```
public abstract class BidirectionalTypeConverter<T, V> extends TypeConverter<T, V>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.core.animation.TypeConverter](https://developer.android.com/reference/androidx/core/animation/TypeConverter)\<T, V\> ||
|   | ↳ | [androidx.core.animation.BidirectionalTypeConverter](https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter) |

*** ** * ** ***

Abstract base class used convert type T to another type V and back again. This is necessary when the value types of in animation are different from the property type. BidirectionalTypeConverter is needed when only the final value for the animation is supplied to animators.

| Parameters |
|---|---|
| `<T>` | type T. It can be converted from and to type V |
| `<V>` | type V. It can be converted from and to type T |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/animation/PropertyValuesHolder#setConverter(androidx.core.animation.TypeConverter)` |   |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter#BidirectionalTypeConverter(java.lang.Class<T>,java.lang.Class<V>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> fromClass, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<V> toClass )` Constructor for creating a bidirectional type converter instance that can convert type T to another type V and back again. |

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T` | `https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter#convertBack(V)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html V value)` Does a conversion from the target type back to the source type. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter<V, T>` | `https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter#invert()()` Returns the inverse of this converter, where the from and to classes are reversed. |

### Inherited methods

From [androidx.core.animation.TypeConverter](https://developer.android.com/reference/androidx/core/animation/TypeConverter) `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html V` `https://developer.android.com/reference/androidx/core/animation/TypeConverter#convert(T)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T value)`

Converts a value from one type to another.

## Public constructors

### BidirectionalTypeConverter

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

```
public BidirectionalTypeConverter(
    @NonNull Class<T> fromClass,
    @NonNull Class<V> toClass
)
```

Constructor for creating a bidirectional type converter instance that can convert type T to another type V and back again.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> fromClass` | class of type T |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<V> toClass` | class of type V |

## Public methods

### convertBack

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

```
public abstract @NonNull T convertBack(@NonNull V value)
```

Does a conversion from the target type back to the source type. The subclass must implement this when a TypeConverter is used in animations and current values will need to be read for an animation.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html V value` | The Object to convert. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html T` | A value of type T, converted from `value`. |

### invert

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

```
public @NonNull BidirectionalTypeConverter<V, T> invert()
```

Returns the inverse of this converter, where the from and to classes are reversed. The inverted converter uses this convert to call `https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter#convertBack(V)` for `https://developer.android.com/reference/androidx/core/animation/TypeConverter#convert(T)` calls and `https://developer.android.com/reference/androidx/core/animation/TypeConverter#convert(T)` for `https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter#convertBack(V)` calls.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/BidirectionalTypeConverter<V, T>` | The inverse of this converter, where the from and to classes are reversed. |