0
interface A1<T> {
    fun f1(t: T)
}
class B1 : A1<Any> {
    override fun f1(t: Any) {
    }
}
interface A2<T: String>: A1<T> {
    fun f2(t: T)
}
class B2 : B1, A2<String> {
    override fun f1(t: String) {
    }

    override fun f2(t: String) {
    }
}

B2 error: Type parameter T of 'A1' has inconsistent values:Any,String

How to solve this problem?

ooftf
  • 11
  • 2
  • 1
    Possible duplicate of [Any way to inherit from same generic interface twice (with separate types) in Kotlin?](https://stackoverflow.com/questions/35528261/any-way-to-inherit-from-same-generic-interface-twice-with-separate-types-in-ko) – Micha Wiedenmann Jan 22 '18 at 10:30
  • There are some similarities – ooftf Jan 22 '18 at 11:01
  • You cannot have two functions f1(t: *) because of type erasure. – Micha Wiedenmann Jan 22 '18 at 11:02
  • There are some similarities In java, this is fine `interface A1{ void f1(T t); } static class B1 implements A1{ @Override public void f1(Object o) { } } interface A2 extends A1{ void f2(T t); } static class B2 extends B1 implements A2 { @Override public void f2(String s) { } }` – ooftf Jan 22 '18 at 11:03
  • Sorry, I was wrong, in java, this is not possible too – ooftf Jan 22 '18 at 11:07
  • Is not only re-implementation of the A2 interface can solve this problem – ooftf Jan 22 '18 at 11:10

0 Answers0