Sometimes, a type is declared to implement 2 interfaces which both have an abstract property the same name, but when I moved the bounded type argument to a top-level abstract superclass and subclass it in different objects, the class overriding the the abstract property on both superinterfaces fails to compile when using type arguments for a subclass.
The generated interfaces and abstract class:
interface Actor : Type {
val login: Stub<String>
val posts: Config<String, BasePostsArgs>
}
interface SomeConflict : Type {
val posts: Config<String, BasePostsArgs>
}
abstract class BasePostsArgs(
args: ArgBuilder = ArgBuilder.create<String, BasePostsArgs>())
: ArgBuilder by args
An example of the generated object which overrides 2 superinterface properties with the same name:
object Organization : Type, SomeConflict, Actor {
override val login: Stub<String> = stub()
override val posts: Config<String, Organization.PostsArgs> = configStub(PostsArgs())
class PostsArgs(args: ArgBuilder = ArgBuilder.create<String, PostsArgs>())
: BasePostsArgs(args) {
fun first(value: Int): PostsArgs = apply { addArg("size", value) }
fun since(value: Date): PostsArgs = apply { addArg("since", value) }
}
}
And then the interfaces for the API:
interface Type {
fun <T> stub(): Stub<T> = StubImpl<T, ArgBuilder>()
fun <T, A : ArgBuilder> configStub(argBuilder: A): Config<T, A> = StubConfigImpl(argBuilder)
}
interface Config<T, A : ArgBuilder> {
fun config(): A
}
interface ArgBuilder {
fun addArg(name: String, value: Any): ArgBuilder
fun <T> build(): Stub<T>
companion object {
fun <T, A: ArgBuilder> create(): ArgBuilder = InternalImplementation<T, A>() as A
}
}
In order to have polymorphism for different fields on types implementing an interface yet requiring different arguments so I can declare them like this:
class OrgPostsQuery(
amount: Int = 100,
from: Date = Date.from(Instant.now())) : Model<Organization> {
val posts by super.model.config()
.first(1000)
.since(from)
.build()
}
(There's a separate set of interfaces for List<T>
for a field like posts
in the example but I left that out for brevity)
What am I doing incorrectly? Or is this not possible?