Code (in interface): ``` @Composable fun <Q> doAct...
# compose
v
Code (in interface):
Copy code
@Composable fun <Q> doAction(input: T, actionCode: Int, actionData: Q? = null)
Error:
Abstract Composable functions cannot have parameters with default values
So, I cant use default parameters in interfaces and because of how interfaces work I cannot override them in the implementation so im just SOL eh. So I am doing my BEST to not scream at the chat (because oh my god im mad) here but I have 2 questions 1. Why shouldn't I be angry as hell about this. This should not have been made this way. 2. What workaround options do I have for this. In the most mild terms, this is a MASSIVE dissapointment and really should be fixed.
h
As a a workaround just create a non abstract function with the default values calling the abstract function.
v
Yes this works but it does require switching from an interface to a abstract class
h
You can provide a default function for an interface. Or use an extension function with the interface as receiver.
r
Would a top level extension function be a suitable workaround?
Copy code
interface Thing<T> {
    @Composable
    fun <Q> doAction(input: T, actionCode: Int, actionData: Q?)
}

@Composable
fun <T> Thing<T>.doAction(input: T, actionCode: Int) =
    doAction<Nothing>(input, actionCode, null)
Edit: Sorry @hfhbd, I just realized that's what you already suggested. I should have read better.
Also, I'm curious what the benefit of the
Q
type is here. Since it's defined on an interface function and only relates to a single argument, what does it gain over
Copy code
fun doAction(input: T, actionCode: Int, actionData: Any?)
v
That's a cool idea I'll see if an extension function works out it may allow me to keep it as an interface. The type that I pass in is mainly there to avoid casting explicitly. I have a function elsewhere that can verify the type and as such avoid the casting warning.