Why can’t type parameter in Kotlin have any other bounds if it’s bounded by another type parameter?

This restrictions was made because java(language) has it:

  interface A {}
  // Error:(7, 26) java: a type variable may not be followed by other bounds
  <T1, T2 extends T1 & A> void test() {} 

And we suppose that this forbidden also in bytecode level.
I dig into it and seems like it is allowed, and scalac generate the following signature:

  // access flags 0x1
  // signature <T1:Ljava/lang/Object;T2:TT1;:LA;>()V
  // declaration: void test<T1, T2T1 extends A>()
  public test()V

So, we probably can support such cases it in the future versions of kotlin.

P.S. As far as I know Kotlin has decidable subtyping, and decidability isn’t affected by this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)