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
hfhbd
01/18/2024, 11:15 AM
As a a workaround just create a non abstract function with the default values calling the abstract function.
v
Vishnu Shrikar
01/18/2024, 12:11 PM
Yes this works but it does require switching from an interface to a abstract class
h
hfhbd
01/18/2024, 12:23 PM
You can provide a default function for an interface. Or use an extension function with the interface as receiver.
r
Ruckus
01/18/2024, 4:42 PM
Would a top level extension function be a suitable workaround?
Edit: Sorry @hfhbd, I just realized that's what you already suggested. I should have read better.
Ruckus
01/18/2024, 4:46 PM
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
Vishnu Shrikar
01/18/2024, 8:28 PM
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.