kevin.cianfarini
05/04/2025, 3:11 AM// An interface in code I define.
interface Thing { ... }
// A type from a third party library.
class SomeThirdPartyType
// An implementation of Thing based on the public API of SomeThirdPartyType that I own.
extension SomeThirdPartyType : Thing { ... }
A really naive implementation of this could generate some wrapper like SomeThirdPartyType$ThingImplWrapper that, whenever an instance of SomeThirdPartyType is referenced as a Thing, it is boxed by the generated wrapper.
Are there unsuspecting ways which something like this might actually be terrible?Youssef Shoaib [MOD]
05/04/2025, 3:12 AMkevin.cianfarini
05/04/2025, 3:15 AMkevin.cianfarini
05/04/2025, 3:38 AMYoussef Shoaib [MOD]
05/04/2025, 3:39 AMinterface Thing<T> and make every operation an extension on T, then you'd take in a Thing context everywhere you want those operations. This is like type classes in other languageskevin.cianfarini
05/04/2025, 1:39 PMinterface Thing<T> {
fun T.doThing()
}kevin.cianfarini
05/04/2025, 1:41 PMTmpod
12/03/2025, 3:56 PMwith(ImplementorObjectForTypeFoo) every time I want to use it. That's way more verbose than it should be, syntax-wise, and much heavier in the final JAR as well.
Is there no better way to achieve it?Tmpod
12/03/2025, 4:01 PMinterface ToFoo {
fun toFoo(): Foo
}
// then
fun T : ToFoo T.bar() = toFoo().let { ... } // whatever logic
// and more methods based on toFooTmpod
12/03/2025, 4:02 PMBar : ToFoo? or equivalentTmpod
12/03/2025, 4:03 PMclass Bar : ToFoo {
override fun toFoo() = ...
}Youssef Shoaib [MOD]
12/03/2025, 5:05 PMTmpod
12/05/2025, 12:14 AM