https://kotlinlang.org logo
Title
v

v79

04/24/2018, 8:44 AM
Can I use a typealias to get around multiple constructors having the same parameter types? e.g.
typealias Prefix = String; class Form(request: Request, prefix: String) { constructor(request: Request, postfix: String) : this(request, "") }
(class abbreviated!)
😢 1
🇳🇴 3
g

gildor

04/24/2018, 8:55 AM
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

v79

04/24/2018, 9:03 AM
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

gildor

04/24/2018, 9:04 AM
Maybe you could provide some example, I’m pretty sure there is some better solution
u

540grunkspin

04/24/2018, 9:05 AM
Can't you use named constructor parameters for this?
class Form(request: Request, prefix: String = "", postfix: String = "")
g

gildor

04/24/2018, 9:09 AM
what do you mean? You of course can call this constuctor:
Form(request, prefix = "[")
Form(request, postfix = "]")
u

540grunkspin

04/24/2018, 9:15 AM
I mean isn't that more or less what @v79 want's or am i missing something?
g

gildor

04/24/2018, 9:18 AM
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

v79

04/24/2018, 9:20 AM
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.