Eric Martori
06/05/2019, 8:51 AMinterface Foo<T> {
fun bar(t: T)
}
And we want to be able to have the same interface but without the parameter:
interface Foo {
fun bar()
}
but this is not possible because we are redeclaring the interface name. A possible solution is to declare Foo<Unit>
and pass Unit
instead of having the second interface without parameters, but this verbose on the calling and declaration site.
We have an extension function fun Foo<Unit>.bar() = bar(Unit)
to make the calling site clearer, but declaring it is still a little bit cumbersome.
Any ideas on how to achieve this?Melih Aksoy
06/05/2019, 9:05 AMinterface Foo {
fun <T> bar(t: T)
fun bar()
}
wbertan
06/05/2019, 9:13 AMFunction0
, Function1
, etc.
interface Foo0 : () -> Unit
interface Foo1<in T> : (T) -> Unit
class A : Foo1<Int> {
override fun invoke(p1: Int) = TODO()
}
class B : Foo0 {
override fun invoke() = TODO()
}
karelpeeters
06/05/2019, 9:16 AMdiesieben07
06/05/2019, 9:19 AMtypealias FooU = Foo<Unit>
Eric Martori
06/05/2019, 9:21 AMwbertan
06/05/2019, 9:24 AMinterface OtherFoo {
fun doSomethingElse()
}
interface Foo0: OtherFoo {
fun doSomething()
}
interface Foo1<in T>: OtherFoo {
fun doSomething(param: T)
}
class A : Foo1<Int> {
override fun doSomething(param: Int) = TODO()
override fun doSomethingElse() = TODO()
}
class B : Foo0 {
override fun doSomething() = TODO()
override fun doSomethingElse() = TODO()
}