In Kotlin, the following seems to be reasonable code:
data class Foo(val bar: String) {
fun combine(other: Foo): Foo {
return Foo(bar + other.bar)
}
companion object Foo {
fun someHelper() {}
}
}
However, it does not compile: type Foo
binds to Foo.Foo
instead of Foo
!
Is that a (language design or compiler) bug, or is this a feature? If the latter, what is the idiomatic way to implement combine
in the presence of a companion object?
Of course, there is what I would consider a workaround:
fun combine(other: my.package.Foo): my.package.Foo {
return Foo(bar + other.bar)
}
But that isn't too nice, now is it?