I'm new to Kotlin. When trying to convert a java application to Kotlin I ran into the following issue so posting this question.
This is a model-view-binder app and here are the java interfaces. Key thing is Model and View are interdependent on each other.
interface Model<T extends View<?>> {}
interface View<T extends Model<?>> {}
class RealModel implements Model<RealView> {}
class RealView implements View<RealModel> {}
class Binder<T extends Model<?>> {
static <ModelT extends Model<?>> Binder<ModelT> of(View<ModelT> view) {}
}
// Application code
Binder<RealModel> binder = Binder.of(new RealView());
binder.bind(new RealModel());
Can I do this in Kotlin?
I tried the following
interface Model<T : View<*>> {}
ERROR: This type parameter violates the Finite Bound Restriction
interface Model<T : View<Any>> {}
ERROR: Type argument is not within its bounds: should be subtype of 'Model<*>'
interface Model<T : View<Model<*>>> {}
ERROR: This type parameter violates the Finite Bound Restriction