implementations to another object, so I'm delegating
Any
like below, is this the right way to do?
Copy code
interface A
class B: A {
override fun toString() = "This is C..."
override fun equals(...) = ...
override fun hashCode() = ...
}
class C(delegated: B): A by delegated, Any by delegated {
// toString(), equals() and hashCode() get `delegated to delegated`?
}
Edit: I'm getting the error:
[DELEGATION_NOT_TO_INTERFACE] Only interfaces can be delegated to
Kien Vu
07/06/2023, 8:16 AM
Since Any is not an interface, my current only solution is:
Copy code
class C(delegated: B): A by delegated {
override fun toString(): String = delegated.toString()
override fun equals(other: Any?): Boolean = delegated == other
override fun hashCode(): Int = delegated.hashCode()
}
c
CLOVIS
07/06/2023, 8:22 AM
Your second message is correct, it's not possible to automatically delegate toString/equals/hashCode