Davio
03/28/2023, 10:51 AMinterface 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?dmitriy.novozhilov
03/28/2023, 10:54 AMRuckus
03/28/2023, 2:52 PMval foo: Foo = FooImpl()
foo.optionalParams("one", "two")
Youssef Shoaib [MOD]
03/28/2023, 3:47 PM_
for unused parameters? That would be a lot more general than just having this for optional parameters. I'm imagining something like this:
class FooImpl : Foo {
override fun optionalParams(one: String, _) {
}
}
or if type specification is absolutely needed:
class FooImpl : Foo {
override fun optionalParams(one: String, _: String?) {
}
}
That would be analogous to the usage of _
in lambdas and restructuring declarationsDavio
03/28/2023, 4:24 PMDavio
03/28/2023, 5:17 PM