Is there a quick and easy way to solve "This type ...
# random
e
Is there a quick and easy way to solve "This type parameter violates the Finite Bound Restriction" I have the following use-case (converting some code from Java to Kotlin):
Copy code
MyClass<T : MyClass<*>>(
    listener: MyListener<T>
)
Essentially my class has a listener which has a callback with the class. It's not beautiful, but it's what I have to work with atm.
y
I've never seen that error before! Does writing it as
MyClass<T : MyClass<T>>
solve the issue? It should because that encoding of self types is very common
e
That does not work. That is what gives me the error I was able to solve it this way:
Copy code
interface Base

MyClass<T: Base>:Base (
  listener: MyListener<T>
)
y
I'm not seeing any errors with:
Copy code
interface MyListener<T: MyClass<T>>
abstract class MyClass<T : MyClass<T>>(
    val listener: MyListener<T>
)
but glad you found a solution regardless!
❤️ 1
I think your issue is using a star-projected type there. When mentioning the bound itself, I get no error. I.e
T: MyClass<T>
works, but
T: MyClass<*>
doesn't
e
You might be right. Let me double check. Maybe I converted it wrong when I anonymized it
@Youssef Shoaib [MOD] I think it was the * that broke things. I'm building now, but it looks correct 🙂 Thanks for calling that out!