Cross references in type parameters
kotlin
Solution
Kotlin doesn't have raw types, you cannot just drop the type parameters.
One option similar to raw types is to use star projections:
abstract class Element<S : Snapshot<*>> { /* ... */ }
abstract class Snapshot<E : Element<*>> { /* ... */ }
But you won't be able to normally work with the type parameters generic members.
Another option is to introduce mutual constraints like this:
abstract class Element<E : Element<E, S>, S : Snapshot<S, E>>() { /* ... */ }
abstract class Snapshot<S : Snapshot<S, E>, E : Element<E, S>>() { /* ... */ }
With this definition, you can be sure that if you define `SomeSnapshot: Snapshot<SomeSnapshot, SomeElement>`, the type `SomeElement` is aware of `SomeSnapshot`, because it is constrained to be derived from `Element<SomeElement, SomeSnapshot>`.
Then the implementation would be:
class SomeElement : Element<SomeElement, SomeSnapshot>() { /* ... */ }
class SomeSnapshot : Snapshot<SomeSnapshot, SomeElement>() { /* ... */ }
Problem
For example in Java I could write: ``` public abstract class Element<S extends Snapshot> { ... } public abstract class Snapshot<E extends Element> { ... } ``` And then, somewhere, extend this classes: ``` public class SnapshotImpl extends Snapshot<ElementImpl> { ... } public class ElementImpl extends Element<SnapshotImpl> { ... } ``` But when I tried to implement same class hierarchy in Kotlin: ``` abstract class Element<S : Snapshot> abstract class Snapshot<E : Element> ``` I got following compilation errors: `Error:(6, 28) Kotlin: One type argument expected for class Snapshot<E> defined in model Error:(6, 25) Kotlin: One type argument expected for class Element<S> defined in model` Is there any way to reproduce same type parameter restrictions in Kotlin?