I'd like to bind two properties of different types to each other bidirectionally.
I have an interface:
interface Gateway<F, T> {
T to(F item);
F from(T item);
}
which allows me to convert an object of one type, to an object of another type.
Optimally, I'd have a function:
void bindBidirectional(Property<F> first, Gateway<F, T> converter, Property<T> second) {
...
}
which would allow me to easily bidirectionally bind two properties, so long as I have an object that can map values of one type to values of another, and back.
How would I implement binding like this?
Note: There are already convenience methods for this kind of binding as long as one of the Property
's types is a String
. I'd like a more generic method, similar to this, that will allow me to convert between any two types.