Hello everyone, I was thinking about a certain fea...
# language-proposals
d
Hello everyone, I was thinking about a certain feature which does not exist, partial implementation of interface functions with optional parameters, for instance this example:
Copy code
interface Foo {
    fun optionalParams(one: String, two: String? = null)
}

class BarImpl: Foo {
    override fun optionalParams(one: String, two: String?) {
    }
}

class FooImpl : Foo {
    override fun optionalParams(one: String) {
    }
}
This does not compile because FooImpl does not override the function correctly, it needs the second parameter, even if you don't use it inside of the function. Would it be possible to add a language feature like this? And would it be a useful idea?
d
What is a usecase for this feature? In which situations it can help?
r
How would you expect this to resolve?
Copy code
val foo: Foo = FooImpl()
foo.optionalParams("one", "two")
1
y
Maybe the compiler could support
_
for unused parameters? That would be a lot more general than just having this for optional parameters. I'm imagining something like this:
Copy code
class FooImpl : Foo {
    override fun optionalParams(one: String, _) {
    }
}
or if type specification is absolutely needed:
Copy code
class FooImpl : Foo {
    override fun optionalParams(one: String, _: String?) {
    }
}
That would be analogous to the usage of
_
in lambdas and restructuring declarations
d
My use case was with various parameters which were part of a search request and, depending on the context, some mattered and some don't, but I recognized I could just bunch together the parameters in a data class and solve it that way. But the idea still intrigued me
It could be resolved because the compiled byte code does have that parameter, but it would just be ignored I guess