Adam Lusch
11/13/2019, 5:49 PMinterface Interface {
fun foo(): Int
}
class Concrete : Interface {
override fun foo() = 42
fun bar() = 1337
}
fun getInterface(): Interface = Concrete()
is it legal to check IsInstance
and "cast" by using the pinned interface pointer as the concrete type?
KotlinInterfaceTest_ExportedSymbols* lib = KotlinInterfaceTest_symbols();
auto sample = lib->kotlin.root.sample;
KotlinInterfaceTest_kref_sample_Interface interface = sample.getInterface();
if (lib->IsInstance(interface.pinned, sample.Concrete._type()))
{
auto concrete = KotlinInterfaceTest_kref_sample_Concrete{ interface.pinned };
printf("Call concrete method: %d\n", sample.Concrete.bar(concrete));
}
This seems to work (prints "Call concrete method: 1337"), but want to make sure I'm not relying on undefined behavior. Thanks!olonho
11/13/2019, 6:51 PMAdam Lusch
11/13/2019, 6:59 PM