hfhbd
02/21/2022, 7:25 PMfun interface A {
fun foo(b: Int = 42) // Single abstract member cannot declare default values
}Umar Ata
02/21/2022, 7:32 PMUmar Ata
02/21/2022, 7:33 PMhfhbd
02/21/2022, 7:35 PMfun modifier to use it as a FunctionalInterface
A { }.foo()Umar Ata
02/21/2022, 7:41 PMJoffrey
02/22/2022, 12:08 AMfun interface is valid and defines functional interfacesJoffrey
02/22/2022, 12:10 AM() -> Unit or a (Int) -> Unit, and I guess that ambiguity could cause problems during SAM conversionshfhbd
02/22/2022, 12:29 AMA { i -> // this?
}
Even with default values in the definition (the interface), you still would need to declare the variables in the body, implementation.
If you mean calling the (single) member foo, the compiler is able to infer the correct overload, like its normal behavior with default values.
Or do you mean this: val a: (Int) -> Unit = A { }? This does not compile, because even a fun interface does not inherit from KFuction (and its invoke) by default.Joffrey
02/22/2022, 12:31 AM