Can I use a typealias to get around multiple const...
# announcements
v
Can I use a typealias to get around multiple constructors having the same parameter types? e.g.
Copy code
typealias Prefix = String; class Form(request: Request, prefix: String) { constructor(request: Request, postfix: String) : this(request, "") }
(class abbreviated!)
🚫 3
😢 1
g
But what is your case? How do you want to distingue those calls? You can do something similar using factory functions, but your original class constructor still should provide some way to separate 2 cases
v
A recursive call requires me to pass a string into the new object. But one of my existing constructors also expects a string used for a different purpose. I'll rework it in some other way. I suppose I could just wrap the string in its own class.
g
Maybe you could provide some example, I’m pretty sure there is some better solution
u
Can't you use named constructor parameters for this?
Copy code
class Form(request: Request, prefix: String = "", postfix: String = "")
g
what do you mean? You of course can call this constuctor:
Copy code
Form(request, prefix = "[")
Form(request, postfix = "]")
u
I mean isn't that more or less what @v79 want's or am i missing something?
g
oh, sorry, yeah, I was confused, thought that this is message from Liam, Yeah this is also my question to Liam, maybe you can solve this in easier, using default arguments or something else
v
I've got so many different constructors going in in this class I should probably have a rethink!
The class is probably trying to do too many different things.